Port account_partner_required to odoo 10
Add technical module account_type_menu
This commit is contained in:
parent
153927075c
commit
8edfc72987
68
account_partner_required/README.rst
Normal file
68
account_partner_required/README.rst
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
||||||
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||||
|
:alt: License: AGPL-3
|
||||||
|
|
||||||
|
========================
|
||||||
|
Account Partner Required
|
||||||
|
========================
|
||||||
|
|
||||||
|
This module adds an option *Partner policy* on account types.
|
||||||
|
|
||||||
|
You have the choice between 3 policies:
|
||||||
|
|
||||||
|
* *optional* (the default policy): partner is optional,
|
||||||
|
* *always*: require a partner,
|
||||||
|
* *never*: forbid a partner.
|
||||||
|
|
||||||
|
This module is useful to enforce a partner on account move lines on
|
||||||
|
customer and supplier accounts.
|
||||||
|
|
||||||
|
This module is very similar to the module *account_analytic_required* available in the OCA project `account-analytic <https://github.com/OCA/account-analytic>`_.
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
=============
|
||||||
|
|
||||||
|
Go to the menu *Accounting > Configuration > Accounting > Account Types* and edit each account types to configure the correct *Partner policy*.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
=====
|
||||||
|
|
||||||
|
If you put a partner on an account move line with an account whose type is configured with *Partner policy* = *never*, you will get an error message.
|
||||||
|
|
||||||
|
If you don't put a partner on an account move line with an account whose type is configured with *Partner policy* = *always*, you will get an error message.
|
||||||
|
|
||||||
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||||
|
:alt: Try me on Runbot
|
||||||
|
:target: https://runbot.odoo-community.org/runbot/92/10.0
|
||||||
|
|
||||||
|
Bug Tracker
|
||||||
|
===========
|
||||||
|
|
||||||
|
Bugs are tracked on `GitHub Issues
|
||||||
|
<https://github.com/OCA/account-financial-tools/issues>`_. In case of trouble, please
|
||||||
|
check there if your issue has already been reported. If you spotted it first,
|
||||||
|
help us smashing it by providing a detailed and welcomed feedback.
|
||||||
|
|
||||||
|
Credits
|
||||||
|
=======
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
|
||||||
|
* Stéphane Bidoul <stephane.bidoul@acsone.eu>
|
||||||
|
* Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
|
||||||
|
Maintainer
|
||||||
|
----------
|
||||||
|
|
||||||
|
.. image:: https://odoo-community.org/logo.png
|
||||||
|
:alt: Odoo Community Association
|
||||||
|
:target: https://odoo-community.org
|
||||||
|
|
||||||
|
This module is maintained by the OCA.
|
||||||
|
|
||||||
|
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||||
|
mission is to support the collaborative development of Odoo features and
|
||||||
|
promote its widespread use.
|
||||||
|
|
||||||
|
To contribute to this module, please visit https://odoo-community.org.
|
@ -1,23 +1,3 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# Account partner required module for OpenERP
|
|
||||||
# Copyright (C) 2014 Acsone (http://acsone.eu).
|
|
||||||
# @author Stéphane Bidoul <stephane.bidoul@acsone.eu>
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
from . import account
|
from . import models
|
||||||
|
@ -1,46 +1,19 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
# © 2014-2016 Acsone (http://acsone.eu).
|
||||||
#
|
# © 2016 Akretion (http://www.akretion.com/)
|
||||||
# Account partner required module for OpenERP
|
# @author Stéphane Bidoul <stephane.bidoul@acsone.eu>
|
||||||
# Copyright (C) 2014 Acsone (http://acsone.eu).
|
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
# @author Stéphane Bidoul <stephane.bidoul@acsone.eu>
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Account partner required',
|
'name': 'Account partner required',
|
||||||
'version': '8.0.0.1.0',
|
'version': '10.0.1.0.0',
|
||||||
'category': 'Generic Modules/Accounting',
|
'category': 'Accounting',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'description': """This module adds an option "partner policy"
|
'summary': "Adds an option 'partner policy' on account types",
|
||||||
on account types.
|
'author': "ACSONE SA/NV,Akretion,Odoo Community Association (OCA)",
|
||||||
|
|
||||||
You have the choice between 3 policies : optional (the default),
|
|
||||||
always (require a partner), and never (forbid a partner).
|
|
||||||
|
|
||||||
This module is useful to enforce a partner on account move lines on
|
|
||||||
customer and supplier accounts.
|
|
||||||
|
|
||||||
Module developed by Stéphane Bidoul <stephane.bidoul@acsone.eu>,
|
|
||||||
inspired by Alexis de Lattre <alexis.delattre@akretion.com>'s
|
|
||||||
account_analytic_required module.
|
|
||||||
""",
|
|
||||||
'author': "ACSONE SA/NV,Odoo Community Association (OCA)",
|
|
||||||
'website': 'http://acsone.eu/',
|
'website': 'http://acsone.eu/',
|
||||||
'depends': ['account'],
|
'depends': ['account_type_menu'],
|
||||||
'data': ['account_view.xml'],
|
'data': ['views/account.xml'],
|
||||||
'installable': False,
|
'installable': True,
|
||||||
}
|
}
|
||||||
|
@ -1,95 +0,0 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# Account partner required module for OpenERP
|
|
||||||
# Copyright (C) 2014 Acsone (http://acsone.eu).
|
|
||||||
# @author Stéphane Bidoul <stephane.bidoul@acsone.eu>
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
from openerp.osv import orm, fields
|
|
||||||
from openerp.tools.translate import _
|
|
||||||
|
|
||||||
|
|
||||||
class account_account_type(orm.Model):
|
|
||||||
_inherit = "account.account.type"
|
|
||||||
|
|
||||||
def _get_policies(self, cr, uid, context=None):
|
|
||||||
"""This is the method to be inherited for adding policies"""
|
|
||||||
return [('optional', _('Optional')),
|
|
||||||
('always', _('Always')),
|
|
||||||
('never', _('Never'))]
|
|
||||||
|
|
||||||
_columns = {
|
|
||||||
'partner_policy': fields.selection(
|
|
||||||
lambda self, *args, **kwargs: self._get_policies(*args, **kwargs),
|
|
||||||
'Policy for partner field',
|
|
||||||
required=True,
|
|
||||||
help="Set the policy for the partner field : if you select "
|
|
||||||
"'Optional', the accountant is free to put a partner "
|
|
||||||
"on an account move line with this type of account ; "
|
|
||||||
"if you select 'Always', the accountant will get an error "
|
|
||||||
"message if there is no partner ; if you select 'Never', "
|
|
||||||
"the accountant will get an error message if a partner "
|
|
||||||
"is present."),
|
|
||||||
}
|
|
||||||
|
|
||||||
_defaults = {
|
|
||||||
'partner_policy': 'optional',
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class account_move_line(orm.Model):
|
|
||||||
_inherit = "account.move.line"
|
|
||||||
|
|
||||||
def _get_partner_policy(self, cr, uid, account, context=None):
|
|
||||||
""" Extension point to obtain analytic policy for an account """
|
|
||||||
return account.user_type.partner_policy
|
|
||||||
|
|
||||||
def _check_partner_required_msg(self, cr, uid, ids, context=None):
|
|
||||||
for move_line in self.browse(cr, uid, ids, context):
|
|
||||||
if move_line.debit == 0 and move_line.credit == 0:
|
|
||||||
continue
|
|
||||||
policy = self._get_partner_policy(cr, uid,
|
|
||||||
move_line.account_id,
|
|
||||||
context=context)
|
|
||||||
if policy == 'always' and not move_line.partner_id:
|
|
||||||
return _("Partner policy is set to 'Always' "
|
|
||||||
"with account %s '%s' but the "
|
|
||||||
"partner is missing in the account "
|
|
||||||
"move line with label '%s'." %
|
|
||||||
(move_line.account_id.code,
|
|
||||||
move_line.account_id.name,
|
|
||||||
move_line.name))
|
|
||||||
elif policy == 'never' and move_line.partner_id:
|
|
||||||
return _("Partner policy is set to 'Never' "
|
|
||||||
"with account %s '%s' but the "
|
|
||||||
"account move line with label '%s' "
|
|
||||||
"has a partner '%s'." %
|
|
||||||
(move_line.account_id.code,
|
|
||||||
move_line.account_id.name,
|
|
||||||
move_line.name,
|
|
||||||
move_line.partner_id.name))
|
|
||||||
|
|
||||||
def _check_partner_required(self, cr, uid, ids, context=None):
|
|
||||||
return not self._check_partner_required_msg(cr, uid, ids,
|
|
||||||
context=context)
|
|
||||||
|
|
||||||
_constraints = [
|
|
||||||
(_check_partner_required,
|
|
||||||
_check_partner_required_msg,
|
|
||||||
['partner_id', 'account_id', 'debit', 'credit']),
|
|
||||||
]
|
|
3
account_partner_required/models/__init__.py
Normal file
3
account_partner_required/models/__init__.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import account
|
79
account_partner_required/models/account.py
Normal file
79
account_partner_required/models/account.py
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# © 2014-2016 Acsone (http://acsone.eu)
|
||||||
|
# © 2016 Akretion (http://www.akretion.com/)
|
||||||
|
# @author Stéphane Bidoul <stephane.bidoul@acsone.eu>
|
||||||
|
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||||
|
|
||||||
|
from odoo import models, fields, api, _
|
||||||
|
from odoo.tools import float_is_zero
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
|
class AccountAccountType(models.Model):
|
||||||
|
_inherit = "account.account.type"
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _get_partner_policies(self):
|
||||||
|
"""This is the method to be inherited for adding policies"""
|
||||||
|
return [('optional', _('Optional')),
|
||||||
|
('always', _('Always')),
|
||||||
|
('never', _('Never'))]
|
||||||
|
|
||||||
|
partner_policy = fields.Selection(
|
||||||
|
_get_partner_policies, string='Policy for Partner Field',
|
||||||
|
required=True, default='optional',
|
||||||
|
help="Set the policy for the partner field : if you select "
|
||||||
|
"'Optional', the accountant is free to put a partner "
|
||||||
|
"on an account move line with this type of account ; "
|
||||||
|
"if you select 'Always', the accountant will get an error "
|
||||||
|
"message if there is no partner ; if you select 'Never', "
|
||||||
|
"the accountant will get an error message if a partner "
|
||||||
|
"is present.")
|
||||||
|
|
||||||
|
|
||||||
|
class AccountAccount(models.Model):
|
||||||
|
_inherit = 'account.account'
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def get_partner_policy(self):
|
||||||
|
""" Extension point to obtain partner policy for an account """
|
||||||
|
self.ensure_one()
|
||||||
|
return self.user_type_id.partner_policy
|
||||||
|
|
||||||
|
|
||||||
|
class AccountMoveLine(models.Model):
|
||||||
|
_inherit = "account.move.line"
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def _check_partner_required_msg(self):
|
||||||
|
prec = self.env.user.company_id.currency_id.rounding
|
||||||
|
for line in self:
|
||||||
|
if (
|
||||||
|
float_is_zero(line.debit, precision_rounding=prec) and
|
||||||
|
float_is_zero(line.credit, precision_rounding=prec)):
|
||||||
|
continue
|
||||||
|
policy = line.account_id.get_partner_policy()
|
||||||
|
if policy == 'always' and not line.partner_id:
|
||||||
|
return _("Partner policy is set to 'Always' "
|
||||||
|
"with account '%s' but the "
|
||||||
|
"partner is missing in the account "
|
||||||
|
"move line with label '%s'." %
|
||||||
|
(line.account_id.name_get()[0][1],
|
||||||
|
line.name))
|
||||||
|
elif policy == 'never' and line.partner_id:
|
||||||
|
return _("Partner policy is set to 'Never' "
|
||||||
|
"with account '%s' but the "
|
||||||
|
"account move line with label '%s' "
|
||||||
|
"has a partner '%s'." %
|
||||||
|
(line.account_id.name_get()[0][1],
|
||||||
|
line.name,
|
||||||
|
line.partner_id.name))
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
@api.constrains('partner_id', 'account_id', 'debit', 'credit')
|
||||||
|
def _check_partner_required(self):
|
||||||
|
for line in self:
|
||||||
|
message = line._check_partner_required_msg()
|
||||||
|
if message:
|
||||||
|
raise ValidationError(message)
|
@ -1,131 +1,132 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
# © 2014-2016 Acsone (http://acsone.eu)
|
||||||
#
|
# © 2016 Akretion (http://www.akretion.com/)
|
||||||
# Account partner required module for OpenERP
|
# @author Stéphane Bidoul <stephane.bidoul@acsone.eu>
|
||||||
# Copyright (C) 2014 Acsone (http://acsone.eu).
|
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
# @author Stéphane Bidoul <stephane.bidoul@acsone.eu>
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from odoo.tests import common
|
||||||
from openerp.tests import common
|
from odoo.exceptions import ValidationError
|
||||||
from openerp.osv import orm
|
|
||||||
|
|
||||||
|
|
||||||
class test_account_partner_required(common.TransactionCase):
|
class TestAccountPartnerRequired(common.TransactionCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(test_account_partner_required, self).setUp()
|
super(TestAccountPartnerRequired, self).setUp()
|
||||||
self.account_obj = self.registry('account.account')
|
self.account_obj = self.env['account.account']
|
||||||
self.account_type_obj = self.registry('account.account.type')
|
self.account_type_obj = self.env['account.account.type']
|
||||||
self.move_obj = self.registry('account.move')
|
self.move_obj = self.env['account.move']
|
||||||
self.move_line_obj = self.registry('account.move.line')
|
self.move_line_obj = self.env['account.move.line']
|
||||||
|
self.sale_journal = self.env['account.journal'].create({
|
||||||
|
'type': 'sale',
|
||||||
|
'code': 'SJXX',
|
||||||
|
'name': 'Sale journal',
|
||||||
|
})
|
||||||
|
liq_acc_type = self.env.ref('account.data_account_type_liquidity')
|
||||||
|
self.account1 = self.account_obj.create({
|
||||||
|
'code': '124242',
|
||||||
|
'name': 'Test 1',
|
||||||
|
'user_type_id': liq_acc_type.id,
|
||||||
|
})
|
||||||
|
self.account_type_custom = self.account_type_obj.create({
|
||||||
|
'name': 'acc type test',
|
||||||
|
'type': 'other',
|
||||||
|
'partner_policy': 'optional',
|
||||||
|
})
|
||||||
|
self.account2 = self.account_obj.create({
|
||||||
|
'code': '124243',
|
||||||
|
'name': 'Test 2',
|
||||||
|
'user_type_id': self.account_type_custom.id,
|
||||||
|
})
|
||||||
|
self.account3 = self.account_obj.create({
|
||||||
|
'code': '124244',
|
||||||
|
'name': 'Test 3',
|
||||||
|
'user_type_id': self.account_type_custom.id,
|
||||||
|
})
|
||||||
|
|
||||||
def _create_move(self, with_partner, amount=100):
|
def _create_move(self, with_partner, amount=100):
|
||||||
date = datetime.now()
|
date = datetime.now()
|
||||||
period_id = self.registry('account.period').find(
|
if with_partner:
|
||||||
self.cr, self.uid, date,
|
partner_id = self.env.ref('base.res_partner_1').id
|
||||||
context={'account_period_prefer_normal': True})[0]
|
else:
|
||||||
|
partner_id = False
|
||||||
move_vals = {
|
move_vals = {
|
||||||
'journal_id': self.ref('account.sales_journal'),
|
'journal_id': self.sale_journal.id,
|
||||||
'period_id': period_id,
|
|
||||||
'date': date,
|
'date': date,
|
||||||
}
|
'line_ids': [
|
||||||
move_id = self.move_obj.create(self.cr, self.uid, move_vals)
|
(0, 0, {
|
||||||
self.move_line_obj.create(self.cr, self.uid,
|
'name': '/',
|
||||||
{'move_id': move_id,
|
'debit': 0,
|
||||||
'name': '/',
|
'credit': amount,
|
||||||
'debit': 0,
|
'account_id': self.account1.id,
|
||||||
'credit': amount,
|
}),
|
||||||
'account_id': self.ref('account.a_sale')})
|
(0, 0, {
|
||||||
move_line_id = self.move_line_obj.create(
|
'name': '/',
|
||||||
self.cr, self.uid,
|
'debit': amount,
|
||||||
{
|
'credit': 0,
|
||||||
'move_id': move_id,
|
'account_id': self.account2.id,
|
||||||
'name': '/',
|
'partner_id': partner_id,
|
||||||
'debit': amount,
|
})
|
||||||
'credit': 0,
|
],
|
||||||
'account_id': self.ref('account.a_recv'),
|
|
||||||
'partner_id': self.ref('base.res_partner_1') if
|
|
||||||
with_partner else False
|
|
||||||
}
|
}
|
||||||
)
|
move = self.move_obj.create(move_vals)
|
||||||
return move_line_id
|
move_line = False
|
||||||
|
for line in move.line_ids:
|
||||||
def _set_partner_policy(self, policy, aref='account.a_recv'):
|
if line.account_id == self.account2:
|
||||||
account_type = self.account_obj.browse(self.cr, self.uid,
|
move_line = line
|
||||||
self.ref(aref)).user_type
|
break
|
||||||
self.account_type_obj.write(self.cr, self.uid, account_type.id,
|
return move_line
|
||||||
{'partner_policy': policy})
|
|
||||||
|
|
||||||
def test_optional(self):
|
def test_optional(self):
|
||||||
self._create_move(with_partner=False)
|
self._create_move(with_partner=False)
|
||||||
self._create_move(with_partner=True)
|
self._create_move(with_partner=True)
|
||||||
|
|
||||||
def test_always_no_partner(self):
|
def test_always_no_partner(self):
|
||||||
self._set_partner_policy('always')
|
self.account_type_custom.partner_policy = 'always'
|
||||||
with self.assertRaises(orm.except_orm):
|
with self.assertRaises(ValidationError):
|
||||||
self._create_move(with_partner=False)
|
self._create_move(with_partner=False)
|
||||||
|
|
||||||
def test_always_no_partner_0(self):
|
def test_always_no_partner_0(self):
|
||||||
# accept missing partner when debit=credit=0
|
# accept missing partner when debit=credit=0
|
||||||
self._set_partner_policy('always')
|
self.account_type_custom.partner_policy = 'always'
|
||||||
self._create_move(with_partner=False, amount=0)
|
self._create_move(with_partner=False, amount=0)
|
||||||
|
|
||||||
def test_always_with_partner(self):
|
def test_always_with_partner(self):
|
||||||
self._set_partner_policy('always')
|
self.account_type_custom.partner_policy = 'always'
|
||||||
self._create_move(with_partner=True)
|
self._create_move(with_partner=True)
|
||||||
|
|
||||||
def test_never_no_partner(self):
|
def test_never_no_partner(self):
|
||||||
self._set_partner_policy('never')
|
self.account_type_custom.partner_policy = 'never'
|
||||||
self._create_move(with_partner=False)
|
self._create_move(with_partner=False)
|
||||||
|
|
||||||
def test_never_with_partner(self):
|
def test_never_with_partner(self):
|
||||||
self._set_partner_policy('never')
|
self.account_type_custom.partner_policy = 'never'
|
||||||
with self.assertRaises(orm.except_orm):
|
with self.assertRaises(ValidationError):
|
||||||
self._create_move(with_partner=True)
|
self._create_move(with_partner=True)
|
||||||
|
|
||||||
def test_never_with_partner_0(self):
|
def test_never_with_partner_0(self):
|
||||||
|
self.account_type_custom.partner_policy = 'never'
|
||||||
# accept partner when debit=credit=0
|
# accept partner when debit=credit=0
|
||||||
self._set_partner_policy('never')
|
|
||||||
self._create_move(with_partner=True, amount=0)
|
self._create_move(with_partner=True, amount=0)
|
||||||
|
|
||||||
def test_always_remove_partner(self):
|
def test_always_remove_partner(self):
|
||||||
# remove partner when policy is always
|
# remove partner when policy is always
|
||||||
self._set_partner_policy('always')
|
self.account_type_custom.partner_policy = 'always'
|
||||||
line_id = self._create_move(with_partner=True)
|
line = self._create_move(with_partner=True)
|
||||||
with self.assertRaises(orm.except_orm):
|
with self.assertRaises(ValidationError):
|
||||||
self.move_line_obj.write(self.cr, self.uid, [line_id],
|
line.write({'partner_id': False})
|
||||||
{'partner_id': False})
|
|
||||||
|
|
||||||
def test_change_account(self):
|
def test_change_account(self):
|
||||||
self._set_partner_policy('always', aref='account.a_pay')
|
self.account_type_custom.partner_policy = 'optional'
|
||||||
line_id = self._create_move(with_partner=False)
|
line = self._create_move(with_partner=False)
|
||||||
# change account to a_pay with policy always but missing partner
|
# change account to an account with policy always but missing partner
|
||||||
with self.assertRaises(orm.except_orm):
|
self.account_type_custom.partner_policy = 'always'
|
||||||
self.move_line_obj.write(self.cr, self.uid, [line_id],
|
with self.assertRaises(ValidationError):
|
||||||
{'account_id': self.ref('account.a_pay')})
|
line.write({'account_id': self.account3.id})
|
||||||
# change account to a_pay with policy always with partner -> ok
|
# change account to an account with policy always with partner
|
||||||
self.move_line_obj.write(
|
line.write({
|
||||||
self.cr,
|
'account_id': self.account3.id,
|
||||||
self.uid,
|
'partner_id': self.env.ref('base.res_partner_1').id
|
||||||
[line_id],
|
})
|
||||||
{
|
|
||||||
'account_id': self.ref('account.a_pay'),
|
|
||||||
'partner_id': self.ref('base.res_partner_1')
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
@ -1,21 +1,19 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
<!--
|
||||||
Account partner required module for OpenERP
|
© 2014-2016 Acsone (http://acsone.eu)
|
||||||
Copyright (C) 2014 Acsone (http://acsone.eu).
|
|
||||||
@author Stéphane Bidoul <stephane.bidoul@acsone.eu>
|
@author Stéphane Bidoul <stephane.bidoul@acsone.eu>
|
||||||
The licence is in the file __openerp__.py
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<openerp>
|
<odoo>
|
||||||
<data>
|
|
||||||
|
|
||||||
<record id="account_partner_required_account_type_form" model="ir.ui.view">
|
<record id="view_account_type_form" model="ir.ui.view">
|
||||||
<field name="name">account_partner_required.account_type_form</field>
|
<field name="name">account_partner_required.account_type_form</field>
|
||||||
<field name="model">account.account.type</field>
|
<field name="model">account.account.type</field>
|
||||||
<field name="inherit_id" ref="account.view_account_type_form" />
|
<field name="inherit_id" ref="account.view_account_type_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="code" position="after">
|
<field name="type" position="after">
|
||||||
<field name="partner_policy" />
|
<field name="partner_policy" />
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
@ -25,11 +23,10 @@
|
|||||||
<field name="model">account.account.type</field>
|
<field name="model">account.account.type</field>
|
||||||
<field name="inherit_id" ref="account.view_account_type_tree" />
|
<field name="inherit_id" ref="account.view_account_type_tree" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="code" position="after">
|
<field name="type" position="after">
|
||||||
<field name="partner_policy" />
|
<field name="partner_policy" />
|
||||||
</field>
|
</field>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</data>
|
</odoo>
|
||||||
</openerp>
|
|
Loading…
Reference in New Issue
Block a user