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

[16.0] account_invoice_supplierinfo_update: fix updating the right supplierinfo #1697

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def _get_supplierinfo(self):
"""Given an invoice line, return the supplierinfo that matches
with product and supplier, if exist"""
self.ensure_one()
supplierinfos = self.product_id.seller_ids.filtered(
lambda seller: seller.partner_id == self.move_id.supplier_partner_id
supplierinfos = self.product_id._select_seller(
partner_id=self.move_id.supplier_partner_id,
quantity=self.quantity,
Copy link
Member

@rvalyi rvalyi Mar 28, 2024

Choose a reason for hiding this comment

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

"Information is a mass noun. It has no plural form"* so infos looks like informations which would be Frenglish and looks TinyERP. Better change that to supplier_info or supplier_data as you want.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi.

@rvalyi. We already talk about that in another PR. summary of the previous comments :

what you mention is not an OCA rule.

  • "infos" is used in many OCA repo. (12 occurences in V16, only in the repos I cloned for GRAP project)
  • "datas" is used in many OCA repo. (19 occurences in V16, only in the repos I cloned for GRAP project)

So if you want to introduce that new rule, please create a dedicated PR here https://github.com/OCA/odoo-community.org/tree/master/website/Contribution

In the meantime, please avoid to block valid PR.

Thanks !

Copy link
Member

Choose a reason for hiding this comment

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

I didn't block, only suggest to use better variable names. When native English speakers read that they feel it's cheap while it's easy to improve.

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't block

You set "changes requested". Could you remove it ?

  1. as said not the place to create new rules. Please create a dedicated issue.

Thanks !

)
return supplierinfos and supplierinfos[0] or False

Expand Down
100 changes: 100 additions & 0 deletions account_invoice_supplierinfo_update/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,106 @@ def setUpClass(cls, chart_template_ref=None):
cls.WizardUpdateSupplierinfo = cls.env["wizard.update.invoice.supplierinfo"]
cls.ProductSupplierinfo = cls.env["product.supplierinfo"]

def test_get_the_right_variant_supplierinfo(self):
# Variant the product A and set a price on variation 1
tmpl_a = self.product_a.product_tmpl_id
tmpl_a.write(
{
"attribute_line_ids": [
(
0,
0,
Comment on lines +51 to +53
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpicking, could be replaced by Command.create

{
"attribute_id": self.env.ref(
"product.product_attribute_2"
).id,
"value_ids": [
(
6,
0,
Comment on lines +59 to +61
Copy link
Contributor

Choose a reason for hiding this comment

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

same here ( Command.set([...]))

[
self.env.ref(
"product.product_attribute_value_3"
).id,
self.env.ref(
"product.product_attribute_value_4"
).id,
],
)
],
},
)
]
}
)
product_a_1, product_a_2 = tmpl_a.product_variant_ids

supplier_product_a_1 = self.env["product.supplierinfo"].create(
[
{
"partner_id": self.invoice.supplier_partner_id.id,
"product_tmpl_id": tmpl_a.id,
"product_id": product_a_1.id,
"price": 30,
}
]
)

# Set the variation 2 on the invoice and run the wizard
self.line_a.write({"product_id": product_a_2, "price_unit": 400})
vals_wizard = self.invoice.check_supplierinfo().get("context", {})
line_ids = vals_wizard.get("default_line_ids", {})

self.assertEqual(line_ids[0][2]["current_price"], False)
self.assertEqual(line_ids[0][2]["new_price"], 400.0)

wizard = self.WizardUpdateSupplierinfo.create(
{"line_ids": line_ids, "invoice_id": self.invoice.id}
)
wizard.update_supplierinfo()

# Supplier of product_a_1 should be not updated and a new supplierinfo
# have been created (to make it simple supplierinfo are always created
# on template)
self.assertEqual(supplier_product_a_1.price, 30)
self.assertEqual(len(tmpl_a.seller_ids), 2)
self.assertEqual(tmpl_a.seller_ids[1].price, 400)
self.assertFalse(tmpl_a.seller_ids[1].product_id)

def test_get_the_right_qty_supplierinfo(self):
tmpl_a = self.product_a.product_tmpl_id
self.env["product.supplierinfo"].create(
[
{
"partner_id": self.invoice.supplier_partner_id.id,
"product_tmpl_id": tmpl_a.id,
"price": 500,
"min_qty": 0,
},
{
"partner_id": self.invoice.supplier_partner_id.id,
"product_tmpl_id": tmpl_a.id,
"price": 300,
"min_qty": 20,
},
]
)

vals_wizard = self.invoice.check_supplierinfo().get("context", {})
line_ids = vals_wizard.get("default_line_ids", {})

self.assertEqual(line_ids[0][2]["current_price"], 500)
self.assertEqual(line_ids[0][2]["new_price"], 400.0)

wizard = self.WizardUpdateSupplierinfo.create(
{"line_ids": line_ids, "invoice_id": self.invoice.id}
)
wizard.update_supplierinfo()

self.assertEqual(len(tmpl_a.seller_ids), 2)
self.assertEqual(tmpl_a.seller_ids[0].price, 300)
self.assertEqual(tmpl_a.seller_ids[1].price, 400)

def test_update_pricelist_supplierinfo(self):
# supplier invoice with pricelist supplierinfo to update and
# product supplierinfo is on product_template
Expand Down