Skip to content

Commit

Permalink
[IMP] sale_order_variant_mgmt: Several improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobaeza committed Sep 30, 2016
1 parent 6167358 commit 82ec3fd
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 17 deletions.
1 change: 1 addition & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ stock-logistics-workflow
stock-logistics-transport
account-closing
server-tools
web
14 changes: 14 additions & 0 deletions sale_order_variant_mgmt/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ selected.
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/167/9.0

Known issues / Roadmap
======================

* The inline button for modifying quantities for an existing line won't
work correctly until these 2 PRs are merged in Odoo:

* https://github.com/odoo/odoo/pull/13558
* https://github.com/odoo/odoo/pull/13635

The corresponding OCB versions are in:

* https://github.com/OCA/OCB/pull/547
* https://github.com/OCA/OCB/pull/548

Credits
=======

Expand Down
149 changes: 149 additions & 0 deletions sale_order_variant_mgmt/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_order_variant_mgmt
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-09-29 17:00+0000\n"
"PO-Revision-Date: 2016-09-29 17:00+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_variant_mgmt
#: model:ir.ui.view,arch_db:sale_order_variant_mgmt.view_order_form
msgid "Add or Modify Variants"
msgstr "Añadir o modificar variantes"

#. module: sale_order_variant_mgmt
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_order_line_product_attribute_value_ids
msgid "Attributes"
msgstr "Atributos"

#. module: sale_order_variant_mgmt
#: model:ir.ui.view,arch_db:sale_order_variant_mgmt.sale_manage_variant_form
msgid "Cancel"
msgstr "Cancelar"

#. module: sale_order_variant_mgmt
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_create_uid
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_line_create_uid
msgid "Created by"
msgstr "Creado por"

#. module: sale_order_variant_mgmt
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_create_date
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_line_create_date
msgid "Created on"
msgstr "Creado en"

#. module: sale_order_variant_mgmt
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_line_disabled
msgid "Disabled"
msgstr "Deshabilitado"

#. module: sale_order_variant_mgmt
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_display_name
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_line_display_name
msgid "Display Name"
msgstr "Nombre mostrado"

#. module: sale_order_variant_mgmt
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_id
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_line_id
msgid "ID"
msgstr "ID (identificación)"

#. module: sale_order_variant_mgmt
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant___last_update
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_line___last_update
msgid "Last Modified on"
msgstr "Última modificación en"

#. module: sale_order_variant_mgmt
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_line_write_uid
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_write_uid
msgid "Last Updated by"
msgstr "Última actualización de"

#. module: sale_order_variant_mgmt
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_line_write_date
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_write_date
msgid "Last Updated on"
msgstr "Última actualización en"

#. module: sale_order_variant_mgmt
#: model:ir.ui.view,arch_db:sale_order_variant_mgmt.sale_manage_variant_form
msgid "Manage Product Variants"
msgstr "Gestionar variantes de productos"

#. module: sale_order_variant_mgmt
#: model:ir.actions.act_window,name:sale_order_variant_mgmt.action_sale_manage_variant
msgid "Manage variants"
msgstr "Gestionar variantes"

#. module: sale_order_variant_mgmt
#: model:ir.ui.view,arch_db:sale_order_variant_mgmt.view_order_form
msgid "Modify Variants"
msgstr "Modificar variantes"

#. module: sale_order_variant_mgmt
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_order_line_product_tmpl_id_sale_order_variant_mgmt
msgid "Product Template"
msgstr "Plantilla producto"

#. module: sale_order_variant_mgmt
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_line_product_uom_qty
msgid "Quantity"
msgstr "Cantidad"

#. module: sale_order_variant_mgmt
#: model:ir.model,name:sale_order_variant_mgmt.model_sale_order_line
msgid "Sales Order Line"
msgstr "Línea pedido de venta"

#. module: sale_order_variant_mgmt
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_product_tmpl_id
msgid "Template"
msgstr "Plantilla"

#. module: sale_order_variant_mgmt
#: model:ir.ui.view,arch_db:sale_order_variant_mgmt.sale_manage_variant_form
msgid "Transfer to order"
msgstr "Transferir al pedido"

#. module: sale_order_variant_mgmt
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_line_value_x
msgid "Value x"
msgstr "Valor x"

#. module: sale_order_variant_mgmt
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_line_value_y
msgid "Value y"
msgstr "Valor y"

#. module: sale_order_variant_mgmt
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_line_product_id
msgid "Variant"
msgstr "Variante"

#. module: sale_order_variant_mgmt
#: model:ir.model.fields,field_description:sale_order_variant_mgmt.field_sale_manage_variant_variant_line_ids
msgid "Variant Lines"
msgstr "Líneas de variantes"

#. module: sale_order_variant_mgmt
#: model:ir.model,name:sale_order_variant_mgmt.model_sale_manage_variant
msgid "sale.manage.variant"
msgstr "sale.manage.variant"

#. module: sale_order_variant_mgmt
#: model:ir.model,name:sale_order_variant_mgmt.model_sale_manage_variant_line
msgid "sale.manage.variant.line"
msgstr "sale.manage.variant.line"

2 changes: 1 addition & 1 deletion sale_order_variant_mgmt/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'

# This field is for avoiding conflicting with sale_stock module that
# This field is for avoiding conflicts with sale_stock module, that
# adds product_tmpl_id, and its possible modifications. This field name
# for sure won't conflict
product_tmpl_id_sale_order_variant_mgmt = fields.Many2one(
Expand Down
4 changes: 3 additions & 1 deletion sale_order_variant_mgmt/views/sale_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="oe_button_box" name="button_box">
<button name="%(action_sale_manage_variant)d"
type="action"
string="Add Variants"
string="Add or Modify Variants"
class="oe_edit_only"
states="draft,sent"
/>
Expand All @@ -20,6 +20,8 @@
<xpath expr="//field[@name='order_line']//tree" position="inside">
<field name="product_tmpl_id_sale_order_variant_mgmt" invisible="1"/>
<field name="product_attribute_value_ids" invisible="1"/>
<!-- Not working until https://github.com/odoo/odoo/pull/13558 -->
<!-- Also https://github.com/odoo/odoo/pull/13635 is needed for correct template selection -->
<button name="%(action_sale_manage_variant)d"
type="action"
string="Modify Variants"
Expand Down
29 changes: 18 additions & 11 deletions sale_order_variant_mgmt/wizard/sale_manage_variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class SaleManageVariant(models.TransientModel):
variant_line_ids = fields.Many2many(
comodel_name='sale.manage.variant.line', string="Variant Lines")

# HACK https://github.com/OCA/server-tools/pull/492#issuecomment-237594285
# HACK: https://github.com/OCA/server-tools/pull/492#issuecomment-237594285
@api.multi
def onchange(self, values, field_name, field_onchange):
if "variant_line_ids" in field_onchange:
for sub in ("product_id", "disabled", "value_x", "value_y",
"value_x_label", "value_y_label", "product_uom_qty"):
"product_uom_qty"):
field_onchange.setdefault("variant_line_ids." + sub, u"")
return super(SaleManageVariant, self).onchange(
values, field_name, field_onchange)
Expand All @@ -28,6 +28,13 @@ def onchange(self, values, field_name, field_onchange):
def _onchange_product_tmpl_id(self):
self.variant_line_ids = [(6, 0, [])]
template = self.product_tmpl_id
context = self.env.context
record = self.env[context['active_model']].browse(
context['active_id'])
if context['active_model'] == 'sale.order.line':
sale_order = record.order_id
else:
sale_order = record
if template and len(template.attribute_line_ids) >= 2:
line_x = template.attribute_line_ids[0]
line_y = template.attribute_line_ids[1]
Expand All @@ -38,21 +45,25 @@ def _onchange_product_tmpl_id(self):
product = template.product_variant_ids.filtered(
lambda x: (value_x in x.attribute_value_ids and
value_y in x.attribute_value_ids))
order_line = sale_order.order_line.filtered(
lambda x: x.product_id == product)
lines.append((0, 0, {
'product_id': product,
'disabled': not bool(product),
'value_x': value_x,
'value_x_label': value_x.name,
'value_y': value_y,
'value_y_label': value_y.name,
'product_uom_qty': 0,
'product_uom_qty': order_line.product_uom_qty,
}))
self.variant_line_ids = lines

@api.multi
def button_transfer_to_order(self):
context = self.env.context
sale_order = self.env['sale.order'].browse(context.get('active_id'))
record = self.env[context['active_model']].browse(context['active_id'])
if context['active_model'] == 'sale.order.line':
sale_order = record.order_id
else:
sale_order = record
OrderLine = self.env['sale.order.line']
for line in self.variant_line_ids:
order_line = sale_order.order_line.filtered(
Expand All @@ -69,7 +80,7 @@ def button_transfer_to_order(self):
'order_id': sale_order.id,
})
order_line.product_id_change()
order_line_vals = order_line.convert_to_write(
order_line_vals = order_line._convert_to_write(
order_line._cache)
sale_order.order_line.create(order_line_vals)

Expand All @@ -82,9 +93,5 @@ class SaleManageVariantLine(models.TransientModel):
disabled = fields.Boolean()
value_x = fields.Many2one(comodel_name='product.attribute.value')
value_y = fields.Many2one(comodel_name='product.attribute.value')
# Direct values as labels are not got from many2one fields and related
# fields are also not computed when drawing the widget
value_x_label = fields.Char()
value_y_label = fields.Char()
product_uom_qty = fields.Float(
string="Quantity", digits_compute=dp.get_precision('Product UoS'))
9 changes: 5 additions & 4 deletions sale_order_variant_mgmt/wizard/sale_manage_variant_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@
<form string="Manage Product Variants">
<group>
<field name="product_tmpl_id"
domain="[('attribute_line_ids', '!=', False)]"
options="{'no_create': True}"/>
domain="[('attribute_line_ids', '!=', False)]"
options="{'no_create': True}"
/>
</group>
<field name="variant_line_ids"
widget="x2many_2d_matrix"
field_x_axis="value_x"
field_label_x_axis="value_x_label"
field_y_axis="value_y"
field_label_y_axis="value_y_label"
field_value = "product_uom_qty"
field_att_disabled="disabled"
x_axis_clickable="0"
y_axis_clickable="0"
/>
<footer>
<button name="button_transfer_to_order"
Expand Down

0 comments on commit 82ec3fd

Please sign in to comment.