Skip to content

Commit

Permalink
Merge 6deed6f into 3ed037e
Browse files Browse the repository at this point in the history
  • Loading branch information
chienandalu committed Nov 12, 2019
2 parents 3ed037e + 6deed6f commit 9b2fecc
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 8 deletions.
Expand Up @@ -130,20 +130,16 @@ def action_accept(self):
# Use preexisting line if any
if wiz_line.sale_line_id:
if wiz_line.units_included:
wiz_line.sale_line_id.update({
"product_uom_qty": wiz_line.units_included,
})
wiz_line.sale_line_id.update(
wiz_line._prepare_update_so_line())
wiz_line.sale_line_id.product_uom_change()
else:
wiz_line.sale_line_id.unlink()
continue
sequence += 1
# Use a new in-memory line otherwise
so_line = so_lines.new({
"order_id": self.order_id.id,
"product_id": wiz_line.product_id.id,
"sequence": sequence,
})
so_line = so_lines.new(
wiz_line._prepare_new_so_line(sequence))
_onchange_method(so_line, ['product_id'])
so_line.product_uom_qty = wiz_line.units_included
_onchange_method(so_line, ['product_uom'])
Expand Down Expand Up @@ -207,3 +203,17 @@ def _compute_price_unit(self):
@api.onchange("units_included")
def _onchange_units_included(self):
self.is_modified = bool(self.sale_line_id or self.units_included)

def _prepare_update_so_line(self):
"""So we can extend PO update"""
return {
"product_uom_qty": self.units_included,
}

def _prepare_new_so_line(self, sequence):
"""So we can extend PO create"""
return {
"order_id": self.wizard_id.order_id.id,
"product_id": self.product_id.id,
"sequence": sequence,
}
@@ -0,0 +1 @@
from . import wizards
21 changes: 21 additions & 0 deletions sale_order_product_recommendation_secondary_unit/__manifest__.py
@@ -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 sale_order_product_recommendation_secondary_unit/i18n/es.po
@@ -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"
@@ -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 ""

@@ -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.

@@ -0,0 +1,3 @@
* `Tecnativa <https://www.tecnativa.com>`_:

* David Vidal <david.vidal@tecnativa.com>
@@ -0,0 +1 @@
This module adds secondary unit to the product recommendation wizard.
@@ -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.
@@ -0,0 +1 @@
from . import sale_order_recommendation
@@ -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
@@ -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>

0 comments on commit 9b2fecc

Please sign in to comment.