-
Notifications
You must be signed in to change notification settings - Fork 70
[ADD] sale_ux: restrict UoM selection to packagings only #1494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| ############################################################################## | ||
| # For copyright and license notices, see __manifest__.py file in module root | ||
| # directory | ||
| ############################################################################## | ||
| import logging | ||
|
|
||
| from odoo import fields, models | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class ProductTemplate(models.Model): | ||
| _inherit = "product.template" | ||
|
|
||
| only_packagings = fields.Boolean( | ||
| default=False, | ||
| help="Indicates that this product is only used as packaging and does not use units.", | ||
| ) | ||
|
|
||
| def _get_available_uoms(self): | ||
| self.ensure_one() | ||
| res = super()._get_available_uoms() | ||
| if self.only_packagings: | ||
| return self.uom_ids | ||
| return res | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -58,3 +58,30 @@ def _compute_discount(self): | |||||
| and not (x.order_id.pricelist_id and x.pricelist_item_id._show_discount()) | ||||||
| ) | ||||||
| super(SaleOrderLine, self - lines)._compute_discount() | ||||||
|
|
||||||
| def _compute_product_uom_id(self): | ||||||
| """Override to respect only_packagings configuration""" | ||||||
| for line in self: | ||||||
| if line.product_id.product_tmpl_id.only_packagings and line.product_id.uom_ids: | ||||||
| if line.product_uom_id and line.product_uom_id in line.product_id.uom_ids: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sería necesario este if con el continue?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fran ! ese if con el continue evaluo el caso donde el usuario elige manualmente la uom. Entonces si se vuelve a ejecutar el compute no fuerza la uom |
||||||
| continue | ||||||
| line.product_uom_id = line.product_id.uom_ids[0] | ||||||
| else: | ||||||
| super()._compute_product_uom_id() | ||||||
|
|
||||||
| @api.depends("product_template_id.only_packagings") | ||||||
|
||||||
| @api.depends("product_template_id.only_packagings") | |
| @api.depends("product_id.product_tmpl_id.only_packagings") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /** @odoo-module **/ | ||
|
|
||
| import { SaleOrderLineProductField } from '@sale/js/sale_product_field'; | ||
| import { patch } from '@web/core/utils/patch'; | ||
|
|
||
| patch(SaleOrderLineProductField. prototype, { | ||
| /** | ||
| * Override to set first packaging as default UoM when only_packagings is True | ||
| */ | ||
| async _openProductConfigurator(edit = false, selectedComboItems = []) { | ||
| const saleOrderLine = this.props.record.data; | ||
| if (saleOrderLine.product_template_id && !edit) { | ||
| const productTemplate = await this.orm.read( | ||
| 'product.template', | ||
| [saleOrderLine.product_template_id.id], | ||
| ['only_packagings', 'uom_ids'] | ||
| ); | ||
| if (productTemplate[0].only_packagings && productTemplate[0].uom_ids.length > 0) { | ||
| await this.props.record.update({ | ||
| product_uom_id: { id: productTemplate[0].uom_ids[0] } | ||
| }); | ||
| } | ||
| } | ||
| return super._openProductConfigurator(edit, selectedComboItems); | ||
| }, | ||
| }); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,14 @@ | ||||||
| <?xml version="1.0"?> | ||||||
| <odoo> | ||||||
| <record id="product_template_form_view" model="ir.ui.view"> | ||||||
| <field name="name">sale_ux.product.form</field> | ||||||
| <field name="model">product.template</field> | ||||||
| <field name="inherit_id" ref="product.product_template_form_view"/> | ||||||
| <field name="priority">30</field> | ||||||
| <field name="arch" type="xml"> | ||||||
| <field name="uom_ids" position="after"> | ||||||
|
||||||
| <field name="uom_ids" position="after"> | |
| <field name="packaging_ids" position="after"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
El texto de ayuda "Indicates that this product is only used as packaging and does not use units" es confuso. El campo no indica que el producto "es un packaging", sino que restringe las UoM disponibles a solo las definidas en los packagings del producto.
Sugerencia de mejora: