Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] shopfloor: Allow to manage supplierinfos on product templates #989

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion shopfloor/actions/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,10 @@ def _product_packaging(self, rec, field):

def _product_supplier_code(self, rec, field):
supplier_info = fields.first(
rec.seller_ids.filtered(lambda x: x.product_id == rec)
rec.seller_ids.filtered(
lambda x: x.product_id == rec
or x.product_tmpl_id == rec.product_tmpl_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
or x.product_tmpl_id == rec.product_tmpl_id
or (x.product_tmpl_id == rec.product_tmpl_id and not x.product_id)

)
)
return supplier_info.product_code or ""

Expand Down
6 changes: 5 additions & 1 deletion shopfloor/actions/data_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ def product_detail(self, record, **kw):
# Defined new method to not overload the base one used in many places
data = self._jsonify(record, self._product_detail_parser, **kw)
suppliers = self.env["product.supplierinfo"].search(
[("product_id", "=", record.id)]
[
"|",
("product_tmpl_id", "=", record.product_tmpl_id.id),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
("product_tmpl_id", "=", record.product_tmpl_id.id),
"&",
("product_tmpl_id", "=", record.product_tmpl_id.id),
("product_id", "=", False),

("product_id", "=", record.id),
]
)
data["suppliers"] = self._jsonify(
suppliers, self._product_supplierinfo_parser, multi=True
Expand Down
5 changes: 4 additions & 1 deletion shopfloor/tests/test_actions_data_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ def _expected_product(self, record, **kw):
return data

def _expected_supplier_code(self, product):
supplier_info = product.seller_ids.filtered(lambda x: x.product_id == product)
supplier_info = product.seller_ids.filtered(
lambda x: x.product_id == product
or x.product_tmpl_id == product.product_tmpl_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
or x.product_tmpl_id == product.product_tmpl_id
or (x.product_tmpl_id == product.product_tmpl_id and not x.product_id)

)
return supplier_info[0].product_code if supplier_info else ""

def _expected_packaging(self, record, **kw):
Expand Down
34 changes: 34 additions & 0 deletions shopfloor/tests/test_actions_data_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,37 @@ def test_product(self):
self.assert_schema(self.schema_detail.product_detail(), data)
expected = self._expected_product_detail(product, full=True)
self.assertDictEqual(data, expected)

def test_product_template(self):
# Check product supplierinfo on template level
move_line = self.move_b.move_line_ids
product = move_line.product_id.with_context(location=move_line.location_id.id)
Partner = self.env["res.partner"].sudo()
manuf = Partner.create({"name": "Manuf 1"})
product.sudo().write(
{
"image_128": fake_colored_image(size=(128, 128)),
"manufacturer_id": manuf.id,
}
)
vendor_a = Partner.create({"name": "Supplier A"})
vendor_b = Partner.create({"name": "Supplier B"})
SupplierInfo = self.env["product.supplierinfo"].sudo()
SupplierInfo.create(
{
"partner_id": vendor_a.id,
"product_tmpl_id": product.product_tmpl_id.id,
"product_code": "SUPP1",
}
)
SupplierInfo.create(
{
"partner_id": vendor_b.id,
"product_tmpl_id": product.product_tmpl_id.id,
"product_code": "SUPP2",
}
)
data = self.data_detail.product_detail(product)
self.assert_schema(self.schema_detail.product_detail(), data)
expected = self._expected_product_detail(product, full=True)
self.assertDictEqual(data, expected)