Skip to content

Commit

Permalink
[MIG] product_supplierinfo_for_customer: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Vang-NguyenPhu committed May 23, 2024
1 parent cc615dd commit 97557b0
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 42 deletions.
4 changes: 4 additions & 0 deletions product_supplierinfo_for_customer/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ Contributors
- Pedro M. Baeza
- Sergio Teruel

- `Komit <https://komit-consulting.com>`__:

- Vang Nguyen Phu

Maintainers
-----------

Expand Down
2 changes: 1 addition & 1 deletion product_supplierinfo_for_customer/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{
"name": "Product Supplierinfo for Customers",
"summary": "Allows to define prices for customers in the products",
"version": "16.0.1.0.1",
"version": "17.0.1.0.0",
"development_status": "Production/Stable",
"author": "AvanzOSC, Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/product-attribute",
Expand Down
1 change: 0 additions & 1 deletion product_supplierinfo_for_customer/demo/product_demo.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2015 AvanzOSC
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo noupdate="1">
Expand Down

This file was deleted.

21 changes: 10 additions & 11 deletions product_supplierinfo_for_customer/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
class ProductProduct(models.Model):
_inherit = "product.product"

def name_get(self):
res = super(ProductProduct, self.with_context(customerinfo=True)).name_get()
return res
def _compute_display_name(self):
return super(

Check warning on line 14 in product_supplierinfo_for_customer/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

product_supplierinfo_for_customer/models/product_product.py#L14

Added line #L14 was not covered by tests
ProductProduct, self.with_context(customerinfo=True)
)._compute_display_name()

@api.model
def _name_search(
self, name="", args=None, operator="ilike", limit=100, name_get_uid=None
self, name="", domain=None, operator="ilike", limit=100, order=None
):
res = super(ProductProduct, self)._name_search(
name, args=args, operator=operator, limit=limit, name_get_uid=name_get_uid
res = super()._name_search(

Check warning on line 22 in product_supplierinfo_for_customer/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

product_supplierinfo_for_customer/models/product_product.py#L22

Added line #L22 was not covered by tests
name, domain=domain, operator=operator, limit=limit, order=order
)
res_ids = list(res)
res_ids_len = len(res_ids)

Check warning on line 26 in product_supplierinfo_for_customer/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

product_supplierinfo_for_customer/models/product_product.py#L25-L26

Added lines #L25 - L26 were not covered by tests
Expand All @@ -41,7 +42,6 @@ def _name_search(
("product_name", operator, name),
],
limit=limit,
access_rights_uid=name_get_uid,
)
if not customerinfo_ids:
return res_ids
Expand All @@ -56,7 +56,6 @@ def _name_search(
self._search(
[("product_tmpl_id", "in", product_tmpls.ids)],
limit=limit,
access_rights_uid=name_get_uid,
)
)
res_ids.extend(product_ids)
Expand All @@ -72,7 +71,7 @@ def _get_price_from_customerinfo(self, partner_id):
return customerinfo.price
return 0.0

def price_compute(
def _price_compute(
self, price_type, uom=False, currency=False, company=None, date=False
):
if price_type == "partner":
Expand All @@ -81,7 +80,7 @@ def price_compute(
) or self.env.context.get("partner", False)
if partner_id and isinstance(partner_id, models.BaseModel):
partner_id = partner_id.id

Check warning on line 82 in product_supplierinfo_for_customer/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

product_supplierinfo_for_customer/models/product_product.py#L82

Added line #L82 was not covered by tests
prices = super().price_compute(
prices = super()._price_compute(
"list_price", uom, currency, company, date=date
)
for product in self:
Expand All @@ -105,7 +104,7 @@ def price_compute(
prices[product.id], currency, company, date
)
return prices
return super().price_compute(price_type, uom, currency, company, date=date)
return super()._price_compute(price_type, uom, currency, company, date=date)

Check warning on line 107 in product_supplierinfo_for_customer/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

product_supplierinfo_for_customer/models/product_product.py#L107

Added line #L107 was not covered by tests

def _prepare_domain_customerinfo(self, params):
self.ensure_one()
Expand Down
12 changes: 5 additions & 7 deletions product_supplierinfo_for_customer/models/product_supplierinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ class ProductSupplierInfo(models.Model):
_inherit = "product.supplierinfo"

@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
res = super().search(args, offset=offset, limit=limit, order=order, count=count)
def search(self, args, offset=0, limit=None, order=None):
res = super().search(args, offset=offset, limit=limit, order=order)
if (
self.env.context.get("customerinfo")
and self._name == "product.supplierinfo"
):
limit2 = limit - len(res) if limit else limit
res2 = self.env["product.customerinfo"].search(

Check warning on line 17 in product_supplierinfo_for_customer/models/product_supplierinfo.py

View check run for this annotation

Codecov / codecov/patch

product_supplierinfo_for_customer/models/product_supplierinfo.py#L16-L17

Added lines #L16 - L17 were not covered by tests
args, offset=offset, limit=limit2, order=order, count=count
args, offset=offset, limit=limit2, order=order
)
res2 = res2.read(list(self.env["product.supplierinfo"]._fields.keys()))

Check warning on line 20 in product_supplierinfo_for_customer/models/product_supplierinfo.py

View check run for this annotation

Codecov / codecov/patch

product_supplierinfo_for_customer/models/product_supplierinfo.py#L20

Added line #L20 was not covered by tests
for result in res2:
Expand All @@ -27,11 +27,9 @@ def read(self, fields=None, load="_classic_read"):
self.env.context.get("customerinfo")
and self._name == "product.supplierinfo"
):
has_ids = self.filtered(
lambda x: x.id in x._ids and isinstance(x.id, (int,))
)
has_ids = self.filtered(lambda x: x.id in x._ids and isinstance(x.id, int))
new_ids = self.filtered(
lambda x: x.id in x._ids and not isinstance(x.id, (int,))
lambda x: x.id in x._ids and not isinstance(x.id, int)
)
return super(ProductSupplierInfo, has_ids).read(
fields=fields, load=load
Expand Down
2 changes: 1 addition & 1 deletion product_supplierinfo_for_customer/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ResPartner(models.Model):

@api.model
def default_get(self, fields):
res = super(ResPartner, self).default_get(fields)
res = super().default_get(fields)
select_type = self.env.context.get("select_type", False)
if select_type:
res.update(
Expand Down
2 changes: 2 additions & 0 deletions product_supplierinfo_for_customer/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
- [Tecnativa](https://www.tecnativa.com):
- Pedro M. Baeza
- Sergio Teruel
- [Komit](https://komit-consulting.com):
- Vang Nguyen Phu
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<li>Sergio Teruel</li>
</ul>
</li>
<li><a class="reference external" href="https://komit-consulting.com">Komit</a>:<ul>
<li>Vang Nguyen Phu</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def _create_partnerinfo(cls, supplierinfo_type, partner, product):
"product_id": product.id,
"product_code": "00001",
"price": 100.0,
"sequence": 10,
}
)

Expand Down Expand Up @@ -88,13 +89,13 @@ def test_product_supplierinfo_price(self):
price, 100.0, "Error: Price not found for product and customer"
)
self.product.company_id = self.company
res = self.product.with_context(partner_id=self.customer.id).price_compute(
res = self.product.with_context(partner_id=self.customer.id)._price_compute(
"partner", self.product.uom_id, self.company.currency_id, self.company
)
self.assertEqual(
res[self.product.id], 100.0, "Error: Wrong price for product and customer"
)
res = self.product.with_context(partner_id=self.unknown.id).price_compute(
res = self.product.with_context(partner_id=self.unknown.id)._price_compute(
"partner", self.product.uom_id, self.company.currency_id, self.company
)
self.assertEqual(
Expand Down Expand Up @@ -166,20 +167,21 @@ def test_variant_supplierinfo_price(self):
"partner_id": self.customer.id,
"product_tmpl_id": template.id,
"price": 30.0,
"sequence": 20,
}
)
res = product.with_context(partner_id=self.customer.id).price_compute(
res = product.with_context(partner_id=self.customer.id)._price_compute(
"partner", product.uom_id, self.company.currency_id, self.company
)
self.assertEqual(res[product.id], 100.0)
res = product_1.with_context(partner_id=self.customer.id).price_compute(
res = product_1.with_context(partner_id=self.customer.id)._price_compute(
"partner", product_1.uom_id, self.company.currency_id, self.company
)
self.assertEqual(res[product_1.id], 30.0)
# Remove template specific price, the price must be the template
# list_price
price_by_template.unlink()
res = product_1.with_context(partner_id=self.customer.id).price_compute(
res = product_1.with_context(partner_id=self.customer.id)._price_compute(
"partner", product_1.uom_id, self.company.currency_id, self.company
)
self.assertEqual(res[product_1.id], 10.0)
9 changes: 4 additions & 5 deletions product_supplierinfo_for_customer/views/product_views.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2015 AvanzOSC
Copyright 2015-18 Tecnativa
Copyright 2017-19 ForgeFlow
Expand Down Expand Up @@ -111,18 +110,18 @@
name="customer_ids"
nolabel="1"
context="{
'default_product_tmpl_id': context.get('product_tmpl_id',active_id),
'default_product_tmpl_id': context.get('product_tmpl_id',id),
'product_template_invisible_variant': True,
}"
attrs="{'invisible': [('product_variant_count','&gt;',1)]}"
invisible="product_variant_count &gt; 1"
/>
<field
name="variant_customer_ids"
nolabel="1"
context="{
'default_product_tmpl_id': context.get('product_tmpl_id',active_id),
'default_product_tmpl_id': context.get('product_tmpl_id',id),
}"
attrs="{'invisible': [('product_variant_count','&lt;=',1)]}"
invisible="product_variant_count &lt;= 1"
/>
</xpath>
</field>
Expand Down

0 comments on commit 97557b0

Please sign in to comment.