Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
245 additions
and
8 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
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 |
21 changes: 21 additions & 0 deletions
21
sale_order_product_recommendation_secondary_unit/__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,21 @@ | ||
# Copyright 2019 David Vidal <david.vidal@tecnativa.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Sale Order Product Recommendation Secondary Unit", | ||
"summary": "Add secondary unit to recommend products wizard", | ||
"version": "11.0.1.0.0", | ||
"category": "Sales", | ||
"website": "https://github.com/OCA/sale-workflow", | ||
"author": "Tecnativa, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"application": False, | ||
"installable": True, | ||
"auto_install": True, | ||
"depends": [ | ||
"sale_order_product_recommendation", | ||
"sale_order_secondary_unit", | ||
], | ||
"data": [ | ||
"wizards/sale_order_recommendation_view.xml", | ||
], | ||
} |
36 changes: 36 additions & 0 deletions
36
sale_order_product_recommendation_secondary_unit/i18n/es.po
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,36 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * sale_order_product_recommendation_secondary_unit | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 11.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2019-10-28 15:17+0000\n" | ||
"PO-Revision-Date: 2019-10-28 15:17+0000\n" | ||
"Last-Translator: <>\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: sale_order_product_recommendation_secondary_unit | ||
#: model:ir.model.fields,field_description:sale_order_product_recommendation_secondary_unit.field_sale_order_recommendation_line_secondary_uom_id | ||
msgid "Default secondary unit for sales" | ||
msgstr "Ud. de venta secundaria por defecto" | ||
|
||
#. module: sale_order_product_recommendation_secondary_unit | ||
#: model:ir.model,name:sale_order_product_recommendation_secondary_unit.model_sale_order_recommendation_line | ||
msgid "Recommended product for current sale order" | ||
msgstr "Producto recomendado para el pedido de venta actual" | ||
|
||
#. module: sale_order_product_recommendation_secondary_unit | ||
#: model:ir.model,name:sale_order_product_recommendation_secondary_unit.model_sale_order_recommendation | ||
msgid "Recommended products for current sale order" | ||
msgstr "Productos recomendados para el pedido de venta actual" | ||
|
||
#. module: sale_order_product_recommendation_secondary_unit | ||
#: model:ir.model.fields,field_description:sale_order_product_recommendation_secondary_unit.field_sale_order_recommendation_line_secondary_uom_qty | ||
msgid "Secondary Qty" | ||
msgstr "Cta. Ud. secundaria" |
37 changes: 37 additions & 0 deletions
37
...t_recommendation_secondary_unit/i18n/sale_order_product_recommendation_secondary_unit.pot
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,37 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * sale_order_product_recommendation_secondary_unit | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 11.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2019-10-28 15:17+0000\n" | ||
"PO-Revision-Date: 2019-10-28 15:17+0000\n" | ||
"Last-Translator: <>\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: sale_order_product_recommendation_secondary_unit | ||
#: model:ir.model.fields,field_description:sale_order_product_recommendation_secondary_unit.field_sale_order_recommendation_line_secondary_uom_id | ||
msgid "Default secondary unit for sales" | ||
msgstr "" | ||
|
||
#. module: sale_order_product_recommendation_secondary_unit | ||
#: model:ir.model,name:sale_order_product_recommendation_secondary_unit.model_sale_order_recommendation_line | ||
msgid "Recommended product for current sale order" | ||
msgstr "" | ||
|
||
#. module: sale_order_product_recommendation_secondary_unit | ||
#: model:ir.model,name:sale_order_product_recommendation_secondary_unit.model_sale_order_recommendation | ||
msgid "Recommended products for current sale order" | ||
msgstr "" | ||
|
||
#. module: sale_order_product_recommendation_secondary_unit | ||
#: model:ir.model.fields,field_description:sale_order_product_recommendation_secondary_unit.field_sale_order_recommendation_line_secondary_uom_qty | ||
msgid "Secondary Qty" | ||
msgstr "" | ||
|
10 changes: 10 additions & 0 deletions
10
sale_order_product_recommendation_secondary_unit/readme/CONFIGURE.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,10 @@ | ||
To configure product secondary units, you need: | ||
|
||
- To have the "Display secondary units" permission. | ||
|
||
Then, in any product form you'll be able to set its product secondary units: | ||
|
||
#. Add an item with its name, unit of measure and factor. | ||
#. Set the product's "Default secondary unit for sales" if you want to have item | ||
recommended by default in such secondary uom. | ||
|
3 changes: 3 additions & 0 deletions
3
sale_order_product_recommendation_secondary_unit/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 <david.vidal@tecnativa.com> |
1 change: 1 addition & 0 deletions
1
sale_order_product_recommendation_secondary_unit/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 adds secondary unit to the product recommendation wizard. |
7 changes: 7 additions & 0 deletions
7
sale_order_product_recommendation_secondary_unit/readme/USAGE.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,7 @@ | ||
To use this module, you need to: | ||
|
||
#. Create a new sale order. | ||
#. Assign its customer. | ||
#. Press *Recommended Products* button. | ||
#. Now you can set the quantities to order from the secondary unit if it's | ||
available for that product. |
1 change: 1 addition & 0 deletions
1
sale_order_product_recommendation_secondary_unit/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 sale_order_recommendation |
94 changes: 94 additions & 0 deletions
94
sale_order_product_recommendation_secondary_unit/wizards/sale_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,94 @@ | ||
# Copyright 2019 David Vidal <david.vidal@tecnativa.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
from odoo.addons import decimal_precision as dp | ||
from odoo.tools.float_utils import float_compare, float_round | ||
|
||
|
||
class SaleOrderRecommendation(models.TransientModel): | ||
_inherit = 'sale.order.recommendation' | ||
|
||
@api.model | ||
def _prepare_wizard_line(self, vals, order_line=False): | ||
res = super()._prepare_wizard_line(vals, order_line) | ||
secondary_uom_id = ( | ||
order_line and order_line.secondary_uom_id or | ||
vals.get('product_id') and | ||
vals['product_id'].sale_secondary_uom_id) | ||
secondary_uom_qty = False | ||
if not order_line and secondary_uom_id: | ||
factor = secondary_uom_id.factor | ||
secondary_uom_qty = ( | ||
res.get('units_included', 0) / (factor or 1.0)) | ||
res['units_included'] = secondary_uom_qty * secondary_uom_id.factor | ||
res.update({ | ||
'secondary_uom_id': secondary_uom_id and secondary_uom_id.id, | ||
'secondary_uom_qty': (order_line and order_line.secondary_uom_qty | ||
or secondary_uom_qty), | ||
}) | ||
return res | ||
|
||
|
||
class SaleOrderRecommendationLine(models.TransientModel): | ||
_inherit = 'sale.order.recommendation.line' | ||
|
||
secondary_uom_id = fields.Many2one( | ||
comodel_name='product.secondary.unit', | ||
related='product_id.sale_secondary_uom_id', | ||
) | ||
secondary_uom_qty = fields.Float( | ||
string='Secondary Qty', | ||
digits=dp.get_precision('Product Unit of Measure'), | ||
) | ||
product_tmpl_id = fields.Many2one( | ||
related='product_id.product_tmpl_id', | ||
readonly=True, | ||
help='To filter secondary uom available', | ||
) | ||
|
||
@api.onchange('secondary_uom_id', 'secondary_uom_qty') | ||
def _onchange_secondary_uom(self): | ||
if not self.secondary_uom_id: | ||
return | ||
factor = self.secondary_uom_id.factor * self.product_id.uom_id.factor | ||
qty = float_round( | ||
self.secondary_uom_qty * factor, | ||
precision_rounding=self.product_id.uom_id.rounding) | ||
if float_compare( | ||
self.units_included, | ||
qty, | ||
precision_rounding=self.product_id.uom_id.rounding) != 0: | ||
self.units_included = qty | ||
|
||
@api.onchange('units_included') | ||
def _onchange_units_included_sale_order_secondary_unit(self): | ||
if not self.secondary_uom_id: | ||
return | ||
factor = self.secondary_uom_id.factor * self.product_id.uom_id.factor | ||
qty = float_round( | ||
self.units_included / (factor or 1.0), | ||
precision_rounding=self.secondary_uom_id.uom_id.rounding) | ||
if float_compare( | ||
self.secondary_uom_qty, | ||
qty, | ||
precision_rounding=self.secondary_uom_id.uom_id.rounding) != 0: | ||
self.secondary_uom_qty = qty | ||
|
||
def _prepare_update_so_line(self): | ||
res = super()._prepare_update_so_line() | ||
if self.secondary_uom_id and self.secondary_uom_qty: | ||
res.update({ | ||
'secondary_uom_id': self.secondary_uom_id.id, | ||
'secondary_uom_qty': self.secondary_uom_qty, | ||
}) | ||
return res | ||
|
||
def _prepare_new_so_line(self, sequence): | ||
res = super()._prepare_new_so_line(sequence) | ||
if self.secondary_uom_id and self.secondary_uom_qty: | ||
res.update({ | ||
'secondary_uom_id': self.secondary_uom_id.id, | ||
'secondary_uom_qty': self.secondary_uom_qty, | ||
}) | ||
return res |
16 changes: 16 additions & 0 deletions
16
sale_order_product_recommendation_secondary_unit/wizards/sale_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"?> | ||
<!-- Copyright 2019 Tecnativa - David Vidal | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<record id="sale_order_recommendation_view_form" model="ir.ui.view"> | ||
<field name="model">sale.order.recommendation</field> | ||
<field name="inherit_id" ref="sale_order_product_recommendation.sale_order_recommendation_view_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="units_included" position="before"> | ||
<field name="product_tmpl_id" invisible="1"/> | ||
<field name="secondary_uom_id" domain="[('product_tmpl_id', '=', product_tmpl_id)]"/> | ||
<field name="secondary_uom_qty" attrs="{'invisible': [('secondary_uom_id', '=', False)]}"/> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |