diff --git a/partner_financial_risk/__openerp__.py b/partner_financial_risk/__openerp__.py index 427a07019..c27b47deb 100644 --- a/partner_financial_risk/__openerp__.py +++ b/partner_financial_risk/__openerp__.py @@ -5,7 +5,7 @@ { 'name': 'Partner Financial Risk', 'summary': 'Manage partner risk', - 'version': '9.0.2.0.0', + 'version': '9.0.2.0.1', 'category': 'Sales Management', 'license': 'AGPL-3', 'author': 'Tecnativa, Odoo Community Association (OCA)', diff --git a/partner_financial_risk/models/res_partner.py b/partner_financial_risk/models/res_partner.py index f5a875b68..71d0bd7e3 100644 --- a/partner_financial_risk/models/res_partner.py +++ b/partner_financial_risk/models/res_partner.py @@ -107,7 +107,7 @@ class ResPartner(models.Model): @api.multi @api.depends( - 'invoice_ids', 'invoice_ids.state', + 'customer', 'invoice_ids', 'invoice_ids.state', 'invoice_ids.amount_total', 'child_ids.invoice_ids', 'child_ids.invoice_ids.state', 'child_ids.invoice_ids.amount_total') @@ -115,11 +115,13 @@ class ResPartner(models.Model): all_partners_and_children = {} all_partner_ids = [] for partner in self.filtered('customer'): + if not partner.id: + continue all_partners_and_children[partner] = self.with_context( active_test=False).search([('id', 'child_of', partner.id)]).ids all_partner_ids += all_partners_and_children[partner] if not all_partner_ids: - return # pragma: no cover + return total_group = self.env['account.invoice'].sudo().read_group( [('type', 'in', ['out_invoice', 'out_refund']), ('state', 'in', ['draft', 'proforma', 'proforma2']), diff --git a/partner_financial_risk/tests/test_partner_financial_risk.py b/partner_financial_risk/tests/test_partner_financial_risk.py index 241fbff77..13feb08e0 100644 --- a/partner_financial_risk/tests/test_partner_financial_risk.py +++ b/partner_financial_risk/tests/test_partner_financial_risk.py @@ -142,3 +142,8 @@ class TestPartnerFinancialRisk(SavepointCase): line.date_maturity = '2017-01-01' self.assertAlmostEqual(self.partner.risk_account_amount, 0.0) self.assertAlmostEqual(self.partner.risk_account_amount_unpaid, 100.0) + + def test_recompute_newid(self): + """Computing risk shouldn't fail if record is a NewId.""" + new = self.env["res.partner"].new({"customer": True}) + new._compute_risk_invoice()