for you marc
This commit is contained in:
parent
776e5aa8f5
commit
23113e9a40
3 changed files with 55 additions and 26 deletions
|
|
@ -11,13 +11,12 @@
|
||||||
""",
|
""",
|
||||||
'license': 'LGPL-3',
|
'license': 'LGPL-3',
|
||||||
'depends': [
|
'depends': [
|
||||||
'purchase',
|
'purchase_stock',
|
||||||
'sale_purchase',
|
'sale_purchase',
|
||||||
'purchase_requisition'
|
'purchase_requisition'
|
||||||
],
|
],
|
||||||
'data': [
|
'data': [
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'views/customer_supplier_requisition_views.xml',
|
|
||||||
'views/purchase_views.xml',
|
'views/purchase_views.xml',
|
||||||
'views/purchase_requisition_views.xml',
|
'views/purchase_requisition_views.xml',
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,64 @@ from odoo import models, fields, api
|
||||||
class PurchaseOrderLine(models.Model):
|
class PurchaseOrderLine(models.Model):
|
||||||
_inherit = 'purchase.order.line'
|
_inherit = 'purchase.order.line'
|
||||||
|
|
||||||
customer_requisition_ref = fields.Char(
|
customer_ids = fields.Many2many(
|
||||||
string='Customer Requisition Ref',
|
related='order_id.requisition_id.customer_ids',
|
||||||
related='order_id.requisition_id.customer_requisition_ref',
|
string='Customers',
|
||||||
store=True,
|
store=True,
|
||||||
help='Customer requisition reference'
|
help='Customers associated with this purchase order line'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
requisition_id = fields.Many2one(
|
||||||
|
related='order_id.requisition_id',
|
||||||
|
string='Purchase Requisition',
|
||||||
|
store=True
|
||||||
|
)
|
||||||
|
|
||||||
|
def _get_product_purchase_description(self, product_lang):
|
||||||
|
name = super()._get_product_purchase_description(product_lang)
|
||||||
|
if self.requisition_id:
|
||||||
|
name = f"[REQ/{self.requisition_id.name}] {name}"
|
||||||
|
if self.customer_ids:
|
||||||
|
name = f"[{', '.join(self.customer_ids.mapped('name'))}] {name}"
|
||||||
|
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)
|
||||||
|
# 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)
|
||||||
|
if existing_line:
|
||||||
|
# Créer une nouvelle ligne au lieu de mettre à jour la quantité
|
||||||
|
res['product_qty'] = product_qty
|
||||||
|
else:
|
||||||
|
res['product_qty'] = product_qty
|
||||||
|
return res
|
||||||
|
|
||||||
@api.model_create_multi
|
@api.model_create_multi
|
||||||
def create(self, vals_list):
|
def create(self, vals_list):
|
||||||
lines = super().create(vals_list)
|
lines = super().create(vals_list)
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.customer_requisition_ref:
|
if line.name:
|
||||||
if line.name:
|
name = line.name
|
||||||
line.name = f"[{line.customer_requisition_ref}] {line.name}"
|
if line.requisition_id:
|
||||||
|
name = f"[REQ/{line.requisition_id.name}] {name}"
|
||||||
|
if line.customer_ids:
|
||||||
|
name = f"[{', '.join(line.customer_ids.mapped('name'))}] {name}"
|
||||||
|
line.name = name
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
|
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
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -3,25 +3,9 @@ from odoo import models, fields, api
|
||||||
class PurchaseRequisition(models.Model):
|
class PurchaseRequisition(models.Model):
|
||||||
_inherit = 'purchase.requisition'
|
_inherit = 'purchase.requisition'
|
||||||
|
|
||||||
customer_id = fields.Many2one(
|
customer_ids = fields.Many2many(
|
||||||
comodel_name='res.partner',
|
comodel_name='res.partner',
|
||||||
string='Customer',
|
string='Customer',
|
||||||
domain=[('customer_rank', '>', 0)],
|
domain=[('customer_rank', '>', 0)],
|
||||||
help='Customer for whom this requisition is created'
|
help='Customer for whom this requisition is created'
|
||||||
)
|
)
|
||||||
|
|
||||||
customer_requisition_ref = fields.Char(
|
|
||||||
string='Customer Requisition Ref',
|
|
||||||
help='Customer requisition reference'
|
|
||||||
)
|
|
||||||
|
|
||||||
def action_in_progress(self):
|
|
||||||
res = super().action_in_progress()
|
|
||||||
for requisition in self:
|
|
||||||
if requisition.customer_requisition_ref:
|
|
||||||
# Update all related PO lines description
|
|
||||||
for po in requisition.purchase_ids:
|
|
||||||
for line in po.order_line:
|
|
||||||
if line.name and not line.name.startswith(f'[{requisition.customer_requisition_ref}]'):
|
|
||||||
line.name = f'[{requisition.customer_requisition_ref}] {line.name}'
|
|
||||||
return res
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue