From 69f815c3f5401092734596703cf1347fff3ee451 Mon Sep 17 00:00:00 2001 From: Marc Durepos Date: Wed, 15 Jan 2025 12:10:16 -0500 Subject: [PATCH] purchase_customer_requisition: module successfully installs --- .../models/purchase_order_line.py | 68 ++++++++++++------- .../models/purchase_requisition.py | 10 +-- .../views/purchase_requisition_views.xml | 14 +--- .../views/purchase_views.xml | 4 +- 4 files changed, 52 insertions(+), 44 deletions(-) diff --git a/purchase_customer_requisition/models/purchase_order_line.py b/purchase_customer_requisition/models/purchase_order_line.py index b5163ce..ef5609c 100644 --- a/purchase_customer_requisition/models/purchase_order_line.py +++ b/purchase_customer_requisition/models/purchase_order_line.py @@ -1,19 +1,23 @@ from odoo import models, fields, api + class PurchaseOrderLine(models.Model): - _inherit = 'purchase.order.line' + _inherit = "purchase.order.line" customer_ids = fields.Many2many( - related='order_id.requisition_id.customer_ids', - string='Customers', + # related='order_id.requisition_id.customer_ids', + string="Customers", store=True, - help='Customers associated with this purchase order line' + help="Customers associated with this purchase order line", ) requisition_id = fields.Many2one( - related='order_id.requisition_id', - string='Purchase Requisition', - store=True + related="order_id.requisition_id", string="Purchase Requisition", store=True + ) + + requisition_name = fields.Char( + related="requisition_id.name", + string="Agreement", ) def _get_product_purchase_description(self, product_lang): @@ -25,16 +29,23 @@ class PurchaseOrderLine(models.Model): return name @api.model - def _prepare_purchase_order_line(self, product_id, product_qty, product_uom, company_id, supplier, po): - res = super()._prepare_purchase_order_line(product_id, product_qty, product_uom, company_id, supplier, po) + def _prepare_purchase_order_line( + self, product_id, product_qty, product_uom, company_id, supplier, po + ): + res = super()._prepare_purchase_order_line( + product_id, product_qty, product_uom, company_id, supplier, po + ) # Si on a une réquisition, on ne veut pas regrouper les lignes if po.requisition_id: - existing_line = po.order_line.filtered(lambda l: l.product_id == product_id and l.requisition_id == po.requisition_id) + existing_line = po.order_line.filtered( + lambda l: l.product_id == product_id + and l.requisition_id == po.requisition_id + ) if existing_line: # Créer une nouvelle ligne au lieu de mettre à jour la quantité - res['product_qty'] = product_qty + res["product_qty"] = product_qty else: - res['product_qty'] = product_qty + res["product_qty"] = product_qty return res @api.model_create_multi @@ -50,17 +61,26 @@ class PurchaseOrderLine(models.Model): line.name = name return lines - def _find_candidate(self, product_id, product_qty, product_uom, location_id, name, origin, company_id, values): + def _find_candidate( + self, + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + company_id, + values, + ): return super( - PurchaseOrderLine, self.filtered(lambda line: not line.requisition_id))._find_candidate( - product_id, - product_qty, - product_uom, - location_id, - name, - origin, - company_id, - values + PurchaseOrderLine, self.filtered(lambda line: not line.requisition_id) + )._find_candidate( + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + company_id, + values, ) - - \ No newline at end of file diff --git a/purchase_customer_requisition/models/purchase_requisition.py b/purchase_customer_requisition/models/purchase_requisition.py index 33fcfa2..229976d 100644 --- a/purchase_customer_requisition/models/purchase_requisition.py +++ b/purchase_customer_requisition/models/purchase_requisition.py @@ -1,11 +1,11 @@ from odoo import models, fields, api + class PurchaseRequisition(models.Model): - _inherit = 'purchase.requisition' + _inherit = "purchase.requisition" customer_ids = fields.Many2many( - comodel_name='res.partner', - string='Customer', - domain=[('customer_rank', '>', 0)], - help='Customer for whom this requisition is created' + comodel_name="res.partner", + string="Applicable Customers", + help="Customer for whom this requisition is applicable", ) diff --git a/purchase_customer_requisition/views/purchase_requisition_views.xml b/purchase_customer_requisition/views/purchase_requisition_views.xml index d4cb6c2..4decae4 100644 --- a/purchase_customer_requisition/views/purchase_requisition_views.xml +++ b/purchase_customer_requisition/views/purchase_requisition_views.xml @@ -6,20 +6,8 @@ - - + - - - purchase.requisition.list.inherit - purchase.requisition - - - - - - - diff --git a/purchase_customer_requisition/views/purchase_views.xml b/purchase_customer_requisition/views/purchase_views.xml index 04b38f1..a431b09 100644 --- a/purchase_customer_requisition/views/purchase_views.xml +++ b/purchase_customer_requisition/views/purchase_views.xml @@ -6,10 +6,10 @@ - + - +