-
-
Notifications
You must be signed in to change notification settings - Fork 746
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by pedrobaeza
- Loading branch information
Showing
11 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import wizards |
20 changes: 20 additions & 0 deletions
20
purchase_order_product_recommendation_brand/__manifest__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2019 David Vidal <david.vidal@tecnativa.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Purchase Order Product Recommendation Brand Filter", | ||
"summary": "Allow to filter recommendations by brand", | ||
"version": "11.0.1.0.0", | ||
"category": "Purchases", | ||
"website": "https://github.com/OCA/purchase-workflow", | ||
"author": "Tecnativa, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"application": False, | ||
"installable": True, | ||
"depends": [ | ||
"purchase_order_product_recommendation", | ||
"product_brand", | ||
], | ||
"data": [ | ||
"wizards/purchase_order_recommendation_view.xml", | ||
], | ||
} |
3 changes: 3 additions & 0 deletions
3
purchase_order_product_recommendation_brand/readme/CONTRIBUTORS.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* `Tecnativa <https://www.tecnativa.com>`_: | ||
|
||
* David Vidal |
1 change: 1 addition & 0 deletions
1
purchase_order_product_recommendation_brand/readme/DESCRIPTION.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This module allows to filter product recommendations by brand. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
To use this module, you need to: | ||
|
||
#. Create a new purchase order. | ||
#. Assign its supplier. | ||
#. Press *Recommended Products* button. | ||
#. Now you can also filter by product brands. |
Binary file added
BIN
+9.23 KB
purchase_order_product_recommendation_brand/static/description/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_recommendation |
43 changes: 43 additions & 0 deletions
43
purchase_order_product_recommendation_brand/tests/test_recommendation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright 2019 Tecnativa | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo.addons.purchase_order_product_recommendation.tests import ( | ||
test_recommendation) | ||
|
||
|
||
class BrandRecommendationCase(test_recommendation.RecommendationCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.brand_obj = cls.env['product.brand'] | ||
cls.brand_1 = cls.brand_obj.create({ | ||
'name': 'OCA Cola', | ||
}) | ||
cls.brand_2 = cls.brand_obj.create({ | ||
'name': 'Play-Odoo', | ||
}) | ||
cls.prod_1.product_brand_id = cls.brand_1 | ||
cls.prod_2.product_brand_id = cls.brand_2 | ||
cls.prod_3.product_brand_id = cls.brand_2 | ||
|
||
def test_recommendations_by_brand(self): | ||
"""We can filter by brand""" | ||
wizard = self.wizard() | ||
wizard.date_begin = wizard.date_end = '2019-02-01' | ||
# Just delivered from brand 1 | ||
wizard.product_brand_ids = self.brand_1 | ||
wizard.show_all_partner_products = True | ||
wizard._generate_recommendations() | ||
# Just one line with products from brand 1 | ||
self.assertEqual(wizard.line_ids.product_id, self.prod_1) | ||
# Just delivered from brand 2 | ||
wizard.product_brand_ids = self.brand_2 | ||
wizard._generate_recommendations() | ||
self.assertEqual(len(wizard.line_ids), 2) | ||
# All brands | ||
wizard.product_brand_ids += self.brand_1 | ||
wizard._generate_recommendations() | ||
self.assertEqual(len(wizard.line_ids), 3) | ||
# No brand set | ||
wizard.product_brand_ids = False | ||
wizard._generate_recommendations() | ||
self.assertEqual(len(wizard.line_ids), 3) |
1 change: 1 addition & 0 deletions
1
purchase_order_product_recommendation_brand/wizards/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import purchase_order_recommendation |
47 changes: 47 additions & 0 deletions
47
purchase_order_product_recommendation_brand/wizards/purchase_order_recommendation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright 2019 Tecnativa | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo import api, fields, models | ||
|
||
|
||
class PurchaseOrderRecommendation(models.TransientModel): | ||
_inherit = 'purchase.order.recommendation' | ||
|
||
product_brand_ids = fields.Many2many( | ||
comodel_name='product.brand', | ||
string="Brands", | ||
) | ||
|
||
def _get_products(self): | ||
"""Filter products of the given brands""" | ||
products = super()._get_products() | ||
# Filter products by brand if set. | ||
# It will apply to show_all_partner_products as well | ||
if self.product_brand_ids: | ||
products = products.filtered( | ||
lambda x: x.product_brand_id in self.product_brand_ids) | ||
return products | ||
|
||
def _get_all_products_domain(self): | ||
"""Filter products of the given brands""" | ||
domain = super()._get_all_products_domain() | ||
if self.product_brand_ids and not self.env.context.get( | ||
'no_brands_filter'): | ||
domain += [('product_brand_id', 'in', self.product_brand_ids.ids)] | ||
return domain | ||
|
||
@api.onchange('product_brand_ids') | ||
def _generate_recommendations(self): | ||
"""Just to add field to the onchange method""" | ||
return super()._generate_recommendations() | ||
|
||
@api.onchange('show_all_partner_products', 'show_all_products') | ||
def _onchange_products(self): | ||
"""Restrict available brands domain""" | ||
products = self._get_supplier_products() | ||
# Gets all products avoiding to filter them by brand again | ||
if self.show_all_products: | ||
products += self.with_context( | ||
no_brands_filter=True).env['product.product'].search( | ||
self._get_all_products_domain()) | ||
brands = products.mapped('product_brand_id') | ||
return {'domain': {'product_brand_ids': [('id', 'in', brands.ids)]}} |
16 changes: 16 additions & 0 deletions
16
purchase_order_product_recommendation_brand/wizards/purchase_order_recommendation_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record id="purchase_order_recommendation_view_form" model="ir.ui.view"> | ||
<field name="model">purchase.order.recommendation</field> | ||
<field name="inherit_id" ref="purchase_order_product_recommendation.purchase_order_recommendation_view_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="warehouse_ids" position="before"> | ||
<field name="product_brand_ids" | ||
widget="many2many_tags" | ||
options="{'no_open': True, 'no_create': True}"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |