[IMP] project_purchase: take into account PO confirmed in project profitability

Before this commit, the PO is only taken into account in the project
profitability if the quantity to invoice or the quantity invoiced is
greater than 0 in its lines. However, we could take into account the PO
when it is confirmed and the products ordered are not delivered to have
an idea on the costs impacted by this PO.

This commit computes the costs impacted by the PO linked to the AA from
the project if the PO is confirmed and there is a quantity ordered or
invoiced or to invoice in its lines. If no quantity to invoice is found
then the amount to invoice will be the price unit of the product
multiplied by the difference between the quantity ordered and the quantity
invoiced.

task-2814466

Part-of: odoo/odoo#88219
This commit is contained in:
Xavier BOL (xbo)
2022-04-08 17:13:30 +02:00
parent e41a8b924c
commit 1a32fbd9c9
+9 -4
View File
@@ -104,16 +104,21 @@ class Project(models.Model):
if self.analytic_account_id:
purchase_order_line_read = self.env['purchase.order.line'].sudo().search_read([
('account_analytic_id', 'in', self.analytic_account_id.ids),
('state', '!=', 'cancel'),
'|', ('qty_invoiced', '>', 0), ('qty_to_invoice', '>', 0),
], ['qty_invoiced', 'qty_to_invoice', 'price_unit'])
('state', 'in', ['purchase', 'done']),
'|',
('qty_invoiced', '>', 0),
'|', ('qty_to_invoice', '>', 0), ('product_uom_qty', '>', 0),
], ['qty_invoiced', 'qty_to_invoice', 'product_uom_qty', 'price_unit'])
if purchase_order_line_read:
amount_invoiced = amount_to_invoice = 0.0
purchase_order_line_ids = []
for pol_read in purchase_order_line_read:
price_unit = pol_read['price_unit']
amount_invoiced -= price_unit * pol_read['qty_invoiced'] if pol_read['qty_invoiced'] > 0 else 0.0
amount_to_invoice -= price_unit * pol_read['qty_to_invoice'] if pol_read['qty_to_invoice'] > 0 else 0.0
if pol_read['qty_to_invoice'] > 0:
amount_to_invoice -= price_unit * pol_read['qty_to_invoice']
else:
amount_to_invoice -= price_unit * (pol_read['product_uom_qty'] - pol_read['qty_invoiced'])
purchase_order_line_ids.append(pol_read['id'])
costs = profitability_items['costs']
section_id = 'purchase_order'