[IMP] project_purchase: allow user to add new purchase order

Before this commit, when the user is in the project update kanban view
and click on Purchase Order row shown in Project Profitability section
in the right side panel, the user cannot create or edit a purchase order
because the AA on each purchase order line is used to link those
purchase orders to the project.

This commit adds the project and also `project_update` key in the
context to use them keys to set the AA on new Purchase Order Line by
default.

task-2861207

closes odoo/odoo#95721

Related: odoo/enterprise#29304
Signed-off-by: Laurent Stukkens (ltu) <ltu@odoo.com>
This commit is contained in:
Xavier BOL (xbo)
2022-07-12 01:29:25 +02:00
parent c227ff755a
commit 2432b4a490
3 changed files with 17 additions and 1 deletions
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import project
from . import purchase_order_line
+1 -1
View File
@@ -40,7 +40,7 @@ class Project(models.Model):
'views': [[False, 'tree'], [False, 'form']],
'domain': [('id', 'in', purchase_orders.ids)],
'context': {
'create': False,
'project_id': self.id,
}
}
if len(purchase_orders) == 1:
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
def _default_account_analytic_id(self):
if self._context.get('project_id'):
return self.env['project.project'].browse(self._context['project_id']).analytic_account_id
return False
account_analytic_id = fields.Many2one(default=_default_account_analytic_id)