Skip to content

Commit

Permalink
fixup! [ADD] beesdoo_product: search product_code of main_seller_id
Browse files Browse the repository at this point in the history
  • Loading branch information
remytms authored and victor-champonnois committed Sep 20, 2022
1 parent 96a420d commit e532f88
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
24 changes: 11 additions & 13 deletions beesdoo_product/models/beesdoo_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,19 @@ class BeesdooProduct(models.Model):
translate=True,
)

main_seller_id = fields.Many2one(
"res.partner",
string="Main Seller",
top_supplierinfo_id = fields.Many2one(
comodel_name="product.supplierinfo",
compute="_compute_main_seller_id",
store=True,
)
main_seller_id = fields.Many2one(
string="Main Seller",
comodel_name="res.partner",
related="top_supplierinfo_id.name",
)
main_seller_id_product_code = fields.Char(
string="Main Seller Product Code",
compute="_compute_main_seller_id",
store=True,
related="top_supplierinfo_id.product_code",
)

display_unit = fields.Many2one("uom.uom")
Expand Down Expand Up @@ -215,9 +218,7 @@ def generate_barcode(self):
self.barcode = bc

@api.multi
@api.depends(
"seller_ids", "seller_ids.date_start", "seller_ids.product_code"
)
@api.depends("seller_ids", "seller_ids.date_start")
def _compute_main_seller_id(self):
for product in self:
# todo english code Calcule le vendeur associé qui a la date de
Expand All @@ -226,11 +227,8 @@ def _compute_main_seller_id(self):
# “seller” and “supplier” are used interchangeably in this
# class. is this on purpose?
sellers_ids = product._get_main_supplier_info()
product.main_seller_id = (
sellers_ids and sellers_ids[0].name or False
)
product.main_seller_id_product_code = (
sellers_ids and sellers_ids[0].product_code or False
product.top_supplierinfo_id = (
sellers_ids and sellers_ids[0] or False
)

@api.multi
Expand Down
8 changes: 4 additions & 4 deletions beesdoo_product/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">beesdoo_product</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/beescoop/addons/tree/12.0/beesdoo_product"><img alt="beescoop/addons" src="https://img.shields.io/badge/github-beescoop%2Faddons-lightgray.png?logo=github" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/beescoop/obeesdoo/tree/12.0/beesdoo_product"><img alt="beescoop/obeesdoo" src="https://img.shields.io/badge/github-beescoop%2Fobeesdoo-lightgray.png?logo=github" /></a></p>
<p>Modification of product module for the needs of beescoop</p>
<ul>
<li><p class="first">Adds the label bio/ethique/provenance.</p>
Expand Down Expand Up @@ -440,10 +440,10 @@ <h1 class="title">beesdoo_product</h1>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/beescoop/addons/issues">GitHub Issues</a>.
<p>Bugs are tracked on <a class="reference external" href="https://github.com/beescoop/obeesdoo/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/beescoop/addons/issues/new?body=module:%20beesdoo_product%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/beescoop/obeesdoo/issues/new?body=module:%20beesdoo_product%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -464,7 +464,7 @@ <h2><a class="toc-backref" href="#id4">Contributors</a></h2>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id5">Maintainers</a></h2>
<p>This module is part of the <a class="reference external" href="https://github.com/beescoop/addons/tree/12.0/beesdoo_product">beescoop/addons</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/beescoop/obeesdoo/tree/12.0/beesdoo_product">beescoop/obeesdoo</a> project on GitHub.</p>
<p>You are welcome to contribute.</p>
</div>
</div>
Expand Down
16 changes: 2 additions & 14 deletions beesdoo_product/tests/test_search_main_seller_product_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@ def setUp(self):
for index, sup in enumerate(self.product2.seller_ids):
sup.product_code = "BBB%d" % index

# Try not to use _get_main_supplier_info as it is a private
# function. I use main_seller_id instead, but main_seller_id
# does not contain the supplierinfo, just the res.partner.
def get_main_supplier_info(product):
for sup in product.seller_ids:
if sup.name == product.main_seller_id:
return sup
return self.env["product.supplierinfo"]

self.product1_main_supplierinfo = get_main_supplier_info(self.product1)
self.product2_main_supplierinfo = get_main_supplier_info(self.product2)

def test_search_product_by_main_seller_product_code(self):
"""
Test searching a product giving the product_code of it's
Expand All @@ -39,7 +27,7 @@ def test_search_product_by_main_seller_product_code(self):
(
"main_seller_id_product_code",
"=",
self.product1_main_supplierinfo.product_code,
self.product1.top_supplierinfo_id.product_code,
)
]
)
Expand All @@ -49,7 +37,7 @@ def test_search_product_by_main_seller_product_code(self):
(
"main_seller_id_product_code",
"=",
self.product2_main_supplierinfo.product_code,
self.product2.top_supplierinfo_id.product_code,
)
]
)
Expand Down

0 comments on commit e532f88

Please sign in to comment.