[IMP] purchase: split compute methods

No advantage to group a search on purchase.order and another one on
account.invoice.
Avoid potential access errors if a user has access to one model but not the
other one.

Closes #25761
This commit is contained in:
Thomas Binsfeld
2018-08-16 17:34:23 +02:00
committed by Martin Trigaux
parent 89273f8d72
commit f9644a7674
+8 -4
View File
@@ -10,11 +10,15 @@ class res_partner(models.Model):
_inherit = 'res.partner'
@api.multi
def _purchase_invoice_count(self):
def _compute_purchase_order_count(self):
PurchaseOrder = self.env['purchase.order']
Invoice = self.env['account.invoice']
for partner in self:
partner.purchase_order_count = PurchaseOrder.search_count([('partner_id', 'child_of', partner.id)])
@api.multi
def _compute_supplier_invoice_count(self):
Invoice = self.env['account.invoice']
for partner in self:
partner.supplier_invoice_count = Invoice.search_count([('partner_id', 'child_of', partner.id), ('type', '=', 'in_invoice')])
@api.model
@@ -24,7 +28,7 @@ class res_partner(models.Model):
property_purchase_currency_id = fields.Many2one(
'res.currency', string="Supplier Currency", company_dependent=True,
help="This currency will be used, instead of the default one, for purchases from the current partner")
purchase_order_count = fields.Integer(compute='_purchase_invoice_count', string='Purchase Order Count')
supplier_invoice_count = fields.Integer(compute='_purchase_invoice_count', string='# Vendor Bills')
purchase_order_count = fields.Integer(compute='_compute_purchase_order_count', string='Purchase Order Count')
supplier_invoice_count = fields.Integer(compute='_compute_supplier_invoice_count', string='# Vendor Bills')
purchase_warn = fields.Selection(WARNING_MESSAGE, 'Purchase Order', help=WARNING_HELP, default="no-message")
purchase_warn_msg = fields.Text('Message for Purchase Order')