Skip to content

Commit

Permalink
[IMP]product_supplierinfo_for_customer_sale: Search SO by customerinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
toita86 committed Dec 23, 2024
1 parent b5a3abf commit 45f622c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
47 changes: 40 additions & 7 deletions product_supplierinfo_for_customer_sale/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,53 @@ class SaleOrderLine(models.Model):
product_customer_code = fields.Char(
compute="_compute_product_customer_code",
string="Product Customer Code",
search="_search_product_customer_code",
)
product_customer_name = fields.Char(
compute="_compute_product_customer_code",
string="Product Customer Name",
search="_search_product_customer_name",
)

@api.depends("product_id")
@api.depends("order_id.partner_id", "product_id", "company_id")
def _compute_product_customer_code(self):
for line in self:
if line.product_id:
supplierinfo = line.product_id._select_customerinfo(
product_customer_name = product_customer_code = False

if line.product_id and line.order_id and line.order_id.partner_id:
customerinfo = line.product_id._select_customerinfo(
partner=line.order_partner_id,
quantity=None,
)
code = supplierinfo.product_code
else:
code = ""
line.product_customer_code = code
product_customer_code = customerinfo.product_code
product_customer_name = customerinfo.product_name

line.product_customer_code = product_customer_code
line.product_customer_name = product_customer_name

def _search_product_customer_code(self, operator, value):
return [

Check warning on line 40 in product_supplierinfo_for_customer_sale/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_supplierinfo_for_customer_sale/models/sale_order_line.py#L40

Added line #L40 was not covered by tests
("product_id.customer_ids.product_code", operator, value),
(
"order_id.partner_id",
"=",
self.env["product.customerinfo"]
.search([("product_code", operator, value)])
.name.id,
),
]

def _search_product_customer_name(self, operator, value):
return [

Check warning on line 52 in product_supplierinfo_for_customer_sale/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_supplierinfo_for_customer_sale/models/sale_order_line.py#L52

Added line #L52 was not covered by tests
("product_id.customer_ids.product_name", operator, value),
(
"order_id.partner_id",
"=",
self.env["product.customerinfo"]
.search([("product_name", operator, value)])
.name.id,
),
]

@api.onchange("product_id")
def product_id_change(self):
Expand Down
20 changes: 20 additions & 0 deletions product_supplierinfo_for_customer_sale/views/sale_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@
</field>
</record>

<record id="sale_order_customerinfo_view_search" model="ir.ui.view">
<field name="name">sale.order.customerinfo.view.search</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_sales_order_filter" />
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']" position="after">
<field
name="order_line"
string="Product Customer Info"
filter_domain="[
'|',
('order_line.product_customer_code', 'ilike', self),
('order_line.product_customer_name', 'ilike', self),
]"
/>
</xpath>
</field>
</record>

<record id="product_customerinfo_tree_view" model="ir.ui.view">
<field name="name">product.customerinfo.tree.view</field>
<field name="model">product.customerinfo</field>
Expand Down

0 comments on commit 45f622c

Please sign in to comment.