diff --git a/account_cost_center/__manifest__.py b/account_cost_center/__manifest__.py index 05c745530..baa774c5f 100644 --- a/account_cost_center/__manifest__.py +++ b/account_cost_center/__manifest__.py @@ -2,25 +2,22 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { - 'name': 'Costcenter', - 'summary': 'Cost center information for invoice lines', - 'author': 'Onestein, Odoo Community Association (OCA)', - 'license': 'AGPL-3', - 'website': 'https://github.com/OCA/account-financial-tools/', - 'category': 'Accounting', - 'version': '12.0.1.0.0', - 'depends': [ - 'account', - 'base_view_inheritance_extension' + "name": "Costcenter", + "summary": "Cost center information for invoice lines", + "author": "Onestein, Odoo Community Association (OCA)", + "license": "AGPL-3", + "website": "https://github.com/OCA/account-financial-tools", + "category": "Accounting", + "version": "12.0.1.0.0", + "depends": ["account", "base_view_inheritance_extension"], + "data": [ + "security/ir.model.access.csv", + "security/account_cost_center_security.xml", + "views/account_cost_center.xml", + "views/account_move.xml", + "views/account_move_line.xml", + "views/account_invoice.xml", + "views/account_invoice_report.xml", ], - 'data': [ - 'security/ir.model.access.csv', - 'security/account_cost_center_security.xml', - 'views/account_cost_center.xml', - 'views/account_move.xml', - 'views/account_move_line.xml', - 'views/account_invoice.xml', - 'views/account_invoice_report.xml', - ], - 'installable': True, + "installable": True, } diff --git a/account_cost_center/models/account_cost_center.py b/account_cost_center/models/account_cost_center.py index 6c53f8d55..21e65da0a 100644 --- a/account_cost_center/models/account_cost_center.py +++ b/account_cost_center/models/account_cost_center.py @@ -5,13 +5,11 @@ from odoo import fields, models class AccountCostCenter(models.Model): - _name = 'account.cost.center' - _description = 'Account Cost Center' + _name = "account.cost.center" + _description = "Account Cost Center" - name = fields.Char(string='Title', required=True) + name = fields.Char(string="Title", required=True) code = fields.Char(required=True) company_id = fields.Many2one( - 'res.company', - string='Company', - default=lambda self: self.env.user.company_id + "res.company", string="Company", default=lambda self: self.env.user.company_id ) diff --git a/account_cost_center/models/account_invoice.py b/account_cost_center/models/account_invoice.py index ceb410f16..ed614300b 100644 --- a/account_cost_center/models/account_invoice.py +++ b/account_cost_center/models/account_invoice.py @@ -5,21 +5,21 @@ from odoo import api, fields, models class AccountInvoice(models.Model): - _inherit = 'account.invoice' + _inherit = "account.invoice" cost_center_id = fields.Many2one( - 'account.cost.center', - string='Cost Center', + "account.cost.center", + string="Cost Center", readonly=True, - states={'draft': [('readonly', False)]}, - help='Default Cost Center', + states={"draft": [("readonly", False)]}, + help="Default Cost Center", ) @api.model def line_get_convert(self, line, part): res = super(AccountInvoice, self).line_get_convert(line, part) - if line.get('cost_center_id'): - res['cost_center_id'] = line['cost_center_id'] + if line.get("cost_center_id"): + res["cost_center_id"] = line["cost_center_id"] return res @api.model @@ -27,9 +27,9 @@ class AccountInvoice(models.Model): res = super(AccountInvoice, self).invoice_line_move_line_get() for dict_data in res: - invl_id = dict_data.get('invl_id') - line = self.env['account.invoice.line'].browse(invl_id) + invl_id = dict_data.get("invl_id") + line = self.env["account.invoice.line"].browse(invl_id) if line.cost_center_id: - dict_data['cost_center_id'] = line.cost_center_id.id + dict_data["cost_center_id"] = line.cost_center_id.id return res diff --git a/account_cost_center/models/account_invoice_line.py b/account_cost_center/models/account_invoice_line.py index f7dbe3aa1..0c56a13de 100644 --- a/account_cost_center/models/account_invoice_line.py +++ b/account_cost_center/models/account_invoice_line.py @@ -5,16 +5,17 @@ from odoo import api, fields, models class AccountInvoiceLine(models.Model): - _inherit = 'account.invoice.line' + _inherit = "account.invoice.line" @api.model def _default_cost_center(self): - return self.env['account.cost.center'].browse( - self.env.context.get('cost_center_id')) + return self.env["account.cost.center"].browse( + self.env.context.get("cost_center_id") + ) cost_center_id = fields.Many2one( - 'account.cost.center', - string='Cost Center', + "account.cost.center", + string="Cost Center", index=True, default=lambda self: self._default_cost_center(), ) diff --git a/account_cost_center/models/account_invoice_report.py b/account_cost_center/models/account_invoice_report.py index 7d13c6866..1b03698bc 100644 --- a/account_cost_center/models/account_invoice_report.py +++ b/account_cost_center/models/account_invoice_report.py @@ -5,22 +5,23 @@ from odoo import fields, models class AccountInvoiceReport(models.Model): - _inherit = 'account.invoice.report' + _inherit = "account.invoice.report" cost_center_id = fields.Many2one( - 'account.cost.center', - string='Cost Center', - readonly=True + "account.cost.center", string="Cost Center", readonly=True ) def _select(self): - return super(AccountInvoiceReport, self)._select() + \ - ", sub.cost_center_id as cost_center_id" + return ( + super(AccountInvoiceReport, self)._select() + + ", sub.cost_center_id as cost_center_id" + ) def _sub_select(self): - return super(AccountInvoiceReport, self)._sub_select() + \ - ", ail.cost_center_id as cost_center_id" + return ( + super(AccountInvoiceReport, self)._sub_select() + + ", ail.cost_center_id as cost_center_id" + ) def _group_by(self): - return super(AccountInvoiceReport, self)._group_by() + \ - ", ail.cost_center_id" + return super(AccountInvoiceReport, self)._group_by() + ", ail.cost_center_id" diff --git a/account_cost_center/models/account_move_line.py b/account_cost_center/models/account_move_line.py index 4b2778173..950389de4 100644 --- a/account_cost_center/models/account_move_line.py +++ b/account_cost_center/models/account_move_line.py @@ -5,10 +5,8 @@ from odoo import fields, models class AccountMoveLine(models.Model): - _inherit = 'account.move.line' + _inherit = "account.move.line" cost_center_id = fields.Many2one( - 'account.cost.center', - index=True, - string='Cost Center' + "account.cost.center", index=True, string="Cost Center" ) diff --git a/account_cost_center/security/account_cost_center_security.xml b/account_cost_center/security/account_cost_center_security.xml index e4635af4f..c78fffe16 100644 --- a/account_cost_center/security/account_cost_center_security.xml +++ b/account_cost_center/security/account_cost_center_security.xml @@ -1,12 +1,17 @@ - + Cost center multi company rule - - - ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] + + + ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] diff --git a/account_cost_center/tests/test_cost_center.py b/account_cost_center/tests/test_cost_center.py index 4189c3e01..29c034552 100644 --- a/account_cost_center/tests/test_cost_center.py +++ b/account_cost_center/tests/test_cost_center.py @@ -5,71 +5,88 @@ from odoo.tests import common class TestAccountCostCenter(common.TransactionCase): - def setUp(self): super(TestAccountCostCenter, self).setUp() - acc_rec = self.env.ref('account.data_account_type_receivable') - acc_exp = self.env.ref('account.data_account_type_expenses') - self.invoice_account = self.env['account.account'].search([ - ('user_type_id', '=', acc_rec.id) - ], limit=1).id - self.invoice_line_account = self.env['account.account'].search([ - ('user_type_id', '=', acc_exp.id)], - limit=1).id + acc_rec = self.env.ref("account.data_account_type_receivable") + acc_exp = self.env.ref("account.data_account_type_expenses") + self.invoice_account = ( + self.env["account.account"] + .search([("user_type_id", "=", acc_rec.id)], limit=1) + .id + ) + self.invoice_line_account = ( + self.env["account.account"] + .search([("user_type_id", "=", acc_exp.id)], limit=1) + .id + ) - self.invoice1 = self.env['account.invoice'].create({ - 'partner_id': self.env.ref('base.res_partner_2').id, - 'account_id': self.invoice_account, - 'type': 'in_invoice', - }) + self.invoice1 = self.env["account.invoice"].create( + { + "partner_id": self.env.ref("base.res_partner_2").id, + "account_id": self.invoice_account, + "type": "in_invoice", + } + ) - self.line1 = self.env['account.invoice.line'].create({ - 'product_id': self.env.ref('product.product_product_2').id, - 'quantity': 1.0, - 'price_unit': 100.0, - 'invoice_id': self.invoice1.id, - 'name': 'product that cost 100', - 'account_id': self.invoice_line_account, - }) + self.line1 = self.env["account.invoice.line"].create( + { + "product_id": self.env.ref("product.product_product_2").id, + "quantity": 1.0, + "price_unit": 100.0, + "invoice_id": self.invoice1.id, + "name": "product that cost 100", + "account_id": self.invoice_line_account, + } + ) - self.costcenter = self.env['account.cost.center'].create({ - 'name': 'Cost Center Test', - 'code': 'CC1', - 'company_id': self.env.user.company_id.id - }) + self.costcenter = self.env["account.cost.center"].create( + { + "name": "Cost Center Test", + "code": "CC1", + "company_id": self.env.user.company_id.id, + } + ) - self.invoice2 = self.env['account.invoice'].create({ - 'partner_id': self.env.ref('base.res_partner_2').id, - 'account_id': self.invoice_account, - 'type': 'in_invoice', - 'cost_center_id': self.costcenter.id, - }) + self.invoice2 = self.env["account.invoice"].create( + { + "partner_id": self.env.ref("base.res_partner_2").id, + "account_id": self.invoice_account, + "type": "in_invoice", + "cost_center_id": self.costcenter.id, + } + ) - self.line2 = self.env['account.invoice.line'].with_context( - cost_center_id=self.costcenter.id).create({ - 'product_id': self.env.ref('product.product_product_4').id, - 'quantity': 1.0, - 'price_unit': 130.0, - 'invoice_id': self.invoice2.id, - 'name': 'product that cost 130', - 'account_id': self.invoice_line_account, - }) + self.line2 = ( + self.env["account.invoice.line"] + .with_context(cost_center_id=self.costcenter.id) + .create( + { + "product_id": self.env.ref("product.product_product_4").id, + "quantity": 1.0, + "price_unit": 130.0, + "invoice_id": self.invoice2.id, + "name": "product that cost 130", + "account_id": self.invoice_line_account, + } + ) + ) def test_01_check_lines(self): self.assertFalse( - self.line1.cost_center_id, - "Default cost center per line not set") + self.line1.cost_center_id, "Default cost center per line not set" + ) self.assertTrue( (self.line2.cost_center_id == self.costcenter), - "Default cost center per line set") + "Default cost center per line set", + ) def test_02_confirm_invoice(self): self.invoice2.action_invoice_open() for move in self.invoice2.move_id.line_ids: cost_center = move.cost_center_id - if move.name == 'product that cost 130': + if move.name == "product that cost 130": self.assertTrue(cost_center) else: self.assertFalse(cost_center) diff --git a/account_cost_center/views/account_cost_center.xml b/account_cost_center/views/account_cost_center.xml index 8f9dc2b8b..030be2694 100644 --- a/account_cost_center/views/account_cost_center.xml +++ b/account_cost_center/views/account_cost_center.xml @@ -1,4 +1,4 @@ - + @@ -9,18 +9,22 @@
-
- + - + @@ -34,9 +38,9 @@ account.cost.center - - - + + + @@ -45,7 +49,11 @@ account.cost.center - + @@ -56,7 +64,7 @@ account.cost.center form tree,form - +

Click to add a new cost center. @@ -68,10 +76,12 @@ - + diff --git a/account_cost_center/views/account_invoice.xml b/account_cost_center/views/account_invoice.xml index cc6dd0ccf..fdd918243 100644 --- a/account_cost_center/views/account_invoice.xml +++ b/account_cost_center/views/account_invoice.xml @@ -1,34 +1,48 @@ - + account.invoice - + - + - - + + - cost_center_id + cost_center_id account.invoice - + - + - - + + - cost_center_id + cost_center_id diff --git a/account_cost_center/views/account_invoice_report.xml b/account_cost_center/views/account_invoice_report.xml index 54bf6a3c0..68f3c3164 100644 --- a/account_cost_center/views/account_invoice_report.xml +++ b/account_cost_center/views/account_invoice_report.xml @@ -1,12 +1,16 @@ - + account.invoice.report - + - + diff --git a/account_cost_center/views/account_move.xml b/account_cost_center/views/account_move.xml index 45a4860fd..551d5a3d5 100644 --- a/account_cost_center/views/account_move.xml +++ b/account_cost_center/views/account_move.xml @@ -1,12 +1,15 @@ - + account.move - + - - + + diff --git a/account_cost_center/views/account_move_line.xml b/account_cost_center/views/account_move_line.xml index 61a03dc5a..ce117e1c8 100644 --- a/account_cost_center/views/account_move_line.xml +++ b/account_cost_center/views/account_move_line.xml @@ -1,23 +1,23 @@ - + account.move.line - + - + account.move.line - + 1 - + diff --git a/setup/account_cost_center/odoo/addons/account_cost_center b/setup/account_cost_center/odoo/addons/account_cost_center new file mode 120000 index 000000000..f96c89e07 --- /dev/null +++ b/setup/account_cost_center/odoo/addons/account_cost_center @@ -0,0 +1 @@ +../../../../account_cost_center \ No newline at end of file diff --git a/setup/account_cost_center/setup.py b/setup/account_cost_center/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/account_cost_center/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)