From 8974d412de602daa649afafeba3dbd6edbb67763 Mon Sep 17 00:00:00 2001 From: Marc Durepos Date: Wed, 13 Sep 2023 11:39:43 -0400 Subject: [PATCH] bemade_multiple_billing_contacts: incorporating views --- .../__manifest__.py | 3 ++- .../models/account_move.py | 2 +- .../models/res_partner.py | 3 +++ .../tests/test_billing_contacts.py | 22 +++++++++++++------ .../views/res_partner_views.xml | 4 +++- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/bemade_multiple_billing_contacts/__manifest__.py b/bemade_multiple_billing_contacts/__manifest__.py index 5e4c2c7..8dd875e 100644 --- a/bemade_multiple_billing_contacts/__manifest__.py +++ b/bemade_multiple_billing_contacts/__manifest__.py @@ -31,7 +31,8 @@ 'account', 'bemade_partner_root_ancestor', ], - 'data': [], + 'data': ['views/account_move_views.xml', + 'views/res_partner_views.xml'], 'demo': [], 'installable': True, 'auto_install': False, diff --git a/bemade_multiple_billing_contacts/models/account_move.py b/bemade_multiple_billing_contacts/models/account_move.py index a12ddda..4dd3e2e 100644 --- a/bemade_multiple_billing_contacts/models/account_move.py +++ b/bemade_multiple_billing_contacts/models/account_move.py @@ -8,7 +8,7 @@ class AccountMove(models.Model): string="Billing Contacts", compute='_compute_billing_contacts', inverse='_inverse_billing_contacts', - store=True) + store=True,) @api.depends('line_ids.sale_line_ids.order_id', 'partner_id') def _compute_billing_contacts(self): diff --git a/bemade_multiple_billing_contacts/models/res_partner.py b/bemade_multiple_billing_contacts/models/res_partner.py index ae988ff..b31327b 100644 --- a/bemade_multiple_billing_contacts/models/res_partner.py +++ b/bemade_multiple_billing_contacts/models/res_partner.py @@ -8,11 +8,14 @@ class Partner(models.Model): comodel_name='res.partner', compute='_compute_billing_contacts', inverse='_inverse_billing_contacts') + potential_billing_contacts = fields.Many2many(comodel_name='res.partner', + compute='_compute_billing_contacts') @api.depends('child_ids.type') def _compute_billing_contacts(self): for rec in self: rec.billing_contacts = rec.child_ids.filtered(lambda r: r.type == 'invoice') + rec.potential_billing_contacts = rec.child_ids | rec.parent_id.child_ids if rec.is_company else None @api.depends('billing_contacts') def _inverse_billing_contacts(self): diff --git a/bemade_multiple_billing_contacts/tests/test_billing_contacts.py b/bemade_multiple_billing_contacts/tests/test_billing_contacts.py index addef96..1329090 100644 --- a/bemade_multiple_billing_contacts/tests/test_billing_contacts.py +++ b/bemade_multiple_billing_contacts/tests/test_billing_contacts.py @@ -34,9 +34,11 @@ class TestBillingContacts(TransactionCase): 'parent_id': cls.parent_co.id, 'type': 'contact', }) - cls.product = cls.env['product.product'].with_company(cls.parent_co.company_id).create({ + cls.product = cls.env['product.product'].with_company( + cls.parent_co.company_id).create({ 'name': 'Product', - 'categ_id': cls.env['product.category'].create({'name': 'Product Category'}).id, + 'categ_id': cls.env['product.category'].create( + {'name': 'Product Category'}).id, 'list_price': 100.0, 'type': 'service', 'uom_id': cls.env.ref('uom.product_uom_unit').id, @@ -70,19 +72,23 @@ class TestBillingContacts(TransactionCase): self.assertTrue(self.non_billing_contact not in self.parent_co.billing_contacts) def test_sale_order_default_billing_contacts(self): - self.assertTrue(self.sale_order.billing_contacts == self.parent_co.billing_contacts) + self.assertTrue( + self.sale_order.billing_contacts == self.parent_co.billing_contacts) def test_sale_order_change_contacts(self): # Test that changing the billing contacts on an SO doesn't change them on the partner - self.sale_order.write({'billing_contacts': [Command.link(self.non_billing_contact.id)]}) - self.assertTrue(all([c in self.sale_order.billing_contacts for c in self.parent_co.billing_contacts])) + self.sale_order.write( + {'billing_contacts': [Command.link(self.non_billing_contact.id)]}) + self.assertTrue(all([c in self.sale_order.billing_contacts for c in + self.parent_co.billing_contacts])) self.assertTrue(self.non_billing_contact not in self.parent_co.billing_contacts) self.assertTrue(self.non_billing_contact in self.sale_order.billing_contacts) def test_sale_order_to_invoice_contacts(self): # Test that the invoices created from sales orders take the billing contacts configured on the SO - self.sale_order.write({'billing_contacts': [Command.link(self.non_billing_contact.id)]}) + self.sale_order.write( + {'billing_contacts': [Command.link(self.non_billing_contact.id)]}) self.sale_order.action_confirm() wiz = self.env['sale.advance.payment.inv'].create({}) @@ -99,10 +105,12 @@ class TestBillingContacts(TransactionCase): self.assertTrue(self.parent_co.billing_contacts == invoice.billing_contacts) def test_invoice_followers_on_validate(self): + # Make sure all billing contacts get added as followers upon validating the invoice self.sale_order.action_confirm() wiz = self.env['sale.advance.payment.inv'].create({}) invoice = wiz._create_invoice(self.sale_order, self.sale_order.order_line[0], self.sale_order.order_line.price_total) invoice.write({'date': datetime.date.today()}) invoice.action_post() - self.assertTrue(all([r in invoice.message_partner_ids for r in self.parent_co.billing_contacts])) + self.assertTrue(all([r in invoice.message_partner_ids for r in + self.parent_co.billing_contacts])) diff --git a/bemade_multiple_billing_contacts/views/res_partner_views.xml b/bemade_multiple_billing_contacts/views/res_partner_views.xml index 6bec7f8..b17c953 100644 --- a/bemade_multiple_billing_contacts/views/res_partner_views.xml +++ b/bemade_multiple_billing_contacts/views/res_partner_views.xml @@ -10,7 +10,9 @@ - +