purchase_customer_requisition: module successfully installs
This commit is contained in:
parent
23113e9a40
commit
69f815c3f5
4 changed files with 52 additions and 44 deletions
|
|
@ -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,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -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",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,20 +6,8 @@
|
|||
<field name="inherit_id" ref="purchase_requisition.view_purchase_requisition_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="vendor_id" position="after">
|
||||
<field name="customer_id"/>
|
||||
<field name="customer_requisition_ref" invisible="not customer_id"/>
|
||||
<field name="customer_ids" widget="many2many_tags"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_purchase_requisition_list_inherit" model="ir.ui.view">
|
||||
<field name="name">purchase.requisition.list.inherit</field>
|
||||
<field name="model">purchase.requisition</field>
|
||||
<field name="inherit_id" ref="purchase_requisition.view_purchase_requisition"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//list" position="inside">
|
||||
<field name="customer_id" optional="show"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@
|
|||
<field name="inherit_id" ref="purchase.purchase_order_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='order_line']/list" position="inside">
|
||||
<field name="customer_requisition_ref" optional="show"/>
|
||||
<field name="requisition_id" optional="show"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='order_line']/form//field[@name='product_id']" position="before">
|
||||
<field name="customer_requisition_ref"/>
|
||||
<field name="requisition_id"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
|
|
|||
Loading…
Reference in a new issue