diff --git a/sale_product_pack_assisted/README.rst b/sale_product_pack_assisted/README.rst new file mode 100644 index 00000000..87a789f4 --- /dev/null +++ b/sale_product_pack_assisted/README.rst @@ -0,0 +1,117 @@ +================= +Sale product Pack +================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--pack-lightgray.png?logo=github + :target: https://github.com/OCA/product-pack/tree/12.0/sale_product_pack + :alt: OCA/product-pack +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/product-pack-12-0/product-pack-12-0-sale_product_pack + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/286/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds *Product Pack* functionality to sales orders. You can choose +a *Pack* in *sales order lines* and see different behaviors depending on +"Pack type" and "Pack component price" fields options selected on this *Pack*. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +#. Go to *Sales > Products > Products*, create or select a product and check + *Is Pack?* +#. Set "Product type" and "Pack component price" fields in the *Pack* page. +#. Add the products to be included in it. +#. Go to *Sales > Orders > Quotations* and create a Quotation. +#. Add a product that has checked "Is Pack?" +#. Save data and you will see an specific behavior depending on "Pack type" and + "Pack component price" fields options selected on this *Pack*. For example, + for products that has *Detailed* option selected in "Pack type" field you + will see one *sale order line* per component that belong to this Pack. + (See *Product pack* module README.rst file) + +Known issues / Roadmap +====================== + +* If this module is installed and stock module is installed too, when you + create a Sale order for a *Non detailed* Pack and you confirm it, + a *Stock picking* is not created with the storable components of that Pack. + So, add a new module called *sale_stock_product_pack* that adds that feature. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* NaN·tic +* ADHOC SA +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Ernesto Tejeda + * Pedro M. Baeza + +* `Akretion `_: + + * Raphaël Reverdy + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-ernestotejeda| image:: https://github.com/ernestotejeda.png?size=40px + :target: https://github.com/ernestotejeda + :alt: ernestotejeda + +Current `maintainer `__: + +|maintainer-ernestotejeda| + +This module is part of the `OCA/product-pack `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_product_pack_assisted/__init__.py b/sale_product_pack_assisted/__init__.py new file mode 100644 index 00000000..83e553ac --- /dev/null +++ b/sale_product_pack_assisted/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/sale_product_pack_assisted/__manifest__.py b/sale_product_pack_assisted/__manifest__.py new file mode 100644 index 00000000..6018d202 --- /dev/null +++ b/sale_product_pack_assisted/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2019 NaN (http://www.nan-tic.com) - Àngel Àlvarez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Assisted Sale product Pack", + "version": "13.0.1.0.0", + "category": "Sales", + "website": "https://github.com/OCA/product-pack", + "author": "NaN·tic, ADHOC SA, Tecnativa, Odoo Community Association (OCA)", + "maintainers": ["jjscarafia"], + "license": "AGPL-3", + "depends": ["sale_product_pack"], + "data": [ + "views/sale_order_line_pack_line_views.xml", + "views/sale_order_line_views.xml", + "views/sale_order_views.xml", + "security/ir.model.access.csv", + ], + "installable": True, + "auto_install": False, + "application": False, +} diff --git a/sale_product_pack_assisted/i18n/es.po b/sale_product_pack_assisted/i18n/es.po new file mode 100644 index 00000000..e520f30d --- /dev/null +++ b/sale_product_pack_assisted/i18n/es.po @@ -0,0 +1,170 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_product_pack_assisted +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-07-06 10:57+0000\n" +"PO-Revision-Date: 2020-07-06 10:57+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_product_pack_assisted +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_sale_order_line__ +msgid "Assisted Pack Lines" +msgstr "Líneas de Pack Asistido" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_sale_order_line__assisted_pack_total +msgid "Assisted Pack Total" +msgstr "Tota de Pack Asistido" + +#. module: sale_product_pack_assisted +#: model_terms:ir.ui.view,arch_db:sale_product_pack_assisted.view_order_line_form2 +msgid "Cancel" +msgstr "Cancelar" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_sale_order_line_pack_line__create_uid +msgid "Created by" +msgstr "" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_sale_order_line_pack_line__create_date +msgid "Created on" +msgstr "" + +#. module: sale_product_pack_assisted +#: model_terms:ir.ui.view,arch_db:sale_product_pack_assisted.view_order_stock_form +msgid "Detail" +msgstr "Detalle" + +#. module: sale_product_pack_assisted +#: code:addons/sale_product_pack_assisted/models/sale_order_line.py:0 +#, python-format +msgid "Details" +msgstr "Detalles" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_sale_order_line_pack_line__discount +msgid "Discount (%)" +msgstr "Descuento (%s)" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_sale_order_line_pack_line__display_name +msgid "Display Name" +msgstr "" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_sale_order_line_pack_line__id +msgid "ID" +msgstr "" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_sale_order_line_pack_line____last_update +msgid "Last Modified on" +msgstr "" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_sale_order_line_pack_line__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_sale_order_line_pack_line__write_date +msgid "Last Updated on" +msgstr "" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields.selection,name:sale_product_pack_assisted.selection__product_template__pack_type__non_detailed_assisted +msgid "Non Detailed - Assisted" +msgstr "No Detallado - Asistido" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields,help:sale_product_pack_assisted.field_product_product__pack_type +#: model:ir.model.fields,help:sale_product_pack_assisted.field_product_template__pack_type +msgid "" +"On sale orders or purchase orders:\n" +"* Detailed: Display components individually in the sale order.\n" +"* Non Detailed: Do not display components individually in the sale order.\n" +"* Non Detailed - Assisted: Do not display components individually in the sale order but gives a template that user can edit to calculate pack amount" +msgstr "" +"En órdenes de venta u órdenes de compra:\n" +"* Detallado: Muestra los componentes individualmente en lineas de la Orden " +"de Venta/Orden de Compra\n" +"* No Detallado: No muestra los componentes individualmente en lineas de la " +"Orden de Venta/Orden de Compra\n" +"* No Detallado - Asistido: No muestra los componentes individualmente en lineas de la " +"Orden de Venta/Orden de Compra pero ofrece una plantilla que el usuario puede utilizar para calcular el importe del pack" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_sale_order_line_pack_line__order_line_id +msgid "Order Line" +msgstr "" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_product_product__pack_type +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_product_template__pack_type +msgid "Pack Type" +msgstr "Tipo de Pack" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_sale_order_line_pack_line__product_id +msgid "Product" +msgstr "Producto" + +#. module: sale_product_pack_assisted +#: model:ir.model,name:sale_product_pack_assisted.model_product_template +msgid "Product Template" +msgstr "Plantilla de producto" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_sale_order_line_pack_line__product_uom_qty +msgid "Quantity" +msgstr "Cantidad" + +#. module: sale_product_pack_assisted +#: model:ir.model,name:sale_product_pack_assisted.model_sale_order_line_pack_line +msgid "Sale Order None Detailed Pack Lines" +msgstr "" + +#. module: sale_product_pack_assisted +#: model:ir.model,name:sale_product_pack_assisted.model_sale_order_line +msgid "Sales Order Line" +msgstr "Línea de pedido de venta" + +#. module: sale_product_pack_assisted +#: model_terms:ir.ui.view,arch_db:sale_product_pack_assisted.view_sale_line_pack_line_tree +msgid "Sales Order Line Pack Lines" +msgstr "" + +#. module: sale_product_pack_assisted +#: model_terms:ir.ui.view,arch_db:sale_product_pack_assisted.view_order_line_form2 +msgid "Sales Order Lines" +msgstr "" + +#. module: sale_product_pack_assisted +#: model_terms:ir.ui.view,arch_db:sale_product_pack_assisted.view_order_line_form2 +msgid "Save" +msgstr "Guardar" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_sale_order_line_pack_line__price_subtotal +msgid "Subtotal" +msgstr "Subtotal" + +#. module: sale_product_pack_assisted +#: model:ir.model.fields,field_description:sale_product_pack_assisted.field_sale_order_line_pack_line__price_unit +msgid "Unit Price" +msgstr "Precio Unitario" + +#. module: sale_product_pack_assisted +#: model_terms:ir.ui.view,arch_db:sale_product_pack_assisted.view_order_line_form2 +msgid "or" +msgstr "o" diff --git a/sale_product_pack_assisted/models/__init__.py b/sale_product_pack_assisted/models/__init__.py new file mode 100644 index 00000000..6d080c0f --- /dev/null +++ b/sale_product_pack_assisted/models/__init__.py @@ -0,0 +1,5 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import sale_order_line_pack_line +from . import sale_order_line +from . import product_template diff --git a/sale_product_pack_assisted/models/product_template.py b/sale_product_pack_assisted/models/product_template.py new file mode 100644 index 00000000..8dff3709 --- /dev/null +++ b/sale_product_pack_assisted/models/product_template.py @@ -0,0 +1,18 @@ +# Copyright 2019 ADHOC SA - Juan José Scarafía +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + pack_type = fields.Selection( + selection_add=[("non_detailed_assisted", "Non Detailed - Assisted")], + help="On sale orders or purchase orders:\n" + "* Detailed: Display components individually in the sale order.\n" + "* Non Detailed: Do not display components individually in the" + " sale order.\n" + "* Non Detailed - Assisted: Do not display components individually in the" + " sale order but gives a template that user can edit to calculate pack amount", + ) diff --git a/sale_product_pack_assisted/models/sale_order_line.py b/sale_product_pack_assisted/models/sale_order_line.py new file mode 100644 index 00000000..664af429 --- /dev/null +++ b/sale_product_pack_assisted/models/sale_order_line.py @@ -0,0 +1,72 @@ +# Copyright 2019 ADHOC SA - Juan José Scarafía +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo import _, api, fields, models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + assisted_pack_line_ids = fields.One2many( + "sale.order.line.pack.line", "order_line_id", "Assisted Pack Lines" + ) + assisted_pack_total = fields.Float(compute="_compute_assisted_pack_total") + + @api.onchange("assisted_pack_total") + def _onchange_pack_line_ids(self): + for line in self: + line.price_unit = line.assisted_pack_total + + @api.depends( + "assisted_pack_line_ids", "assisted_pack_line_ids.price_subtotal", + ) + def _compute_assisted_pack_total(self): + for line in self: + line.assisted_pack_total = sum( + x.price_subtotal for x in line.assisted_pack_line_ids + ) + + def expand_pack_line(self, write=False): + self.ensure_one() + # if we are using update_pricelist or checking out on ecommerce we + # only want to update prices + do_not_expand = self._context.get("update_prices") or self._context.get( + "update_pricelist", False + ) + if not do_not_expand and self.product_id.pack_type == "non_detailed_assisted": + # remove previus existing lines + self.assisted_pack_line_ids.unlink() + + # create a sale pack line for each product pack line + for pack_line in self.product_id.pack_line_ids.with_context( + pricelist=self.order_id.pricelist_id.id + ): + price_unit = pack_line.product_id.price + quantity = pack_line.quantity + vals = { + "order_line_id": self.id, + "product_id": pack_line.product_id.id, + "product_uom_qty": quantity, + "price_unit": price_unit, + "discount": pack_line.sale_discount, + "price_subtotal": price_unit * quantity, + } + self.assisted_pack_line_ids.create(vals) + return super().expand_pack_line(write) + + def action_assisted_pack_detail(self): + view = self.env.ref("sale_product_pack_assisted.view_order_line_form2") + return { + "name": _("Details"), + "view_type": "form", + "view_mode": "form", + "res_model": "sale.order.line", + "view_id": view.id, + "type": "ir.actions.act_window", + "target": "new", + "readonly": True, + "res_id": self.id, + "context": dict(self.env.context, pricelist=self.order_id.pricelist_id.id), + } + + def button_save_data(self): + return True diff --git a/sale_product_pack_assisted/models/sale_order_line_pack_line.py b/sale_product_pack_assisted/models/sale_order_line_pack_line.py new file mode 100644 index 00000000..339a62dc --- /dev/null +++ b/sale_product_pack_assisted/models/sale_order_line_pack_line.py @@ -0,0 +1,35 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from odoo import api, fields, models + + +class SaleOrderLinePackLine(models.Model): + _name = "sale.order.line.pack.line" + _description = "Sale Order None Detailed Pack Lines" + + order_line_id = fields.Many2one( + "sale.order.line", "Order Line", ondelete="cascade", index=True, required=True + ) + product_id = fields.Many2one("product.product", "Product", required=True) + price_unit = fields.Float("Unit Price", required=True, digits="Product Price") + discount = fields.Float("Discount (%)", digits="Discount",) + price_subtotal = fields.Float( + compute="_compute_price_subtotal", string="Subtotal", digits="Account" + ) + product_uom_qty = fields.Float("Quantity", digits="Product UoS", required=True) + + @api.onchange("product_id") + def onchange_product_id(self): + for line in self: + line.price_unit = line.product_id.price + + @api.depends("price_unit", "product_uom_qty") + def _compute_price_subtotal(self): + for line in self: + line.price_subtotal = ( + line.product_uom_qty + * line.price_unit + * (1 - (line.discount or 0.0) / 100.0) + ) diff --git a/sale_product_pack_assisted/security/ir.model.access.csv b/sale_product_pack_assisted/security/ir.model.access.csv new file mode 100644 index 00000000..9d005f1c --- /dev/null +++ b/sale_product_pack_assisted/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_sale_order_line_pack_line_user,sale_order_line_pack_line_user,model_sale_order_line_pack_line,base.group_user,1,1,1,1 +access_sale_order_line_pack_line_all,sale_order_line_pack_line_all,model_sale_order_line_pack_line,,1,0,0,0 diff --git a/sale_product_pack_assisted/views/sale_order_line_pack_line_views.xml b/sale_product_pack_assisted/views/sale_order_line_pack_line_views.xml new file mode 100644 index 00000000..9f1f1044 --- /dev/null +++ b/sale_product_pack_assisted/views/sale_order_line_pack_line_views.xml @@ -0,0 +1,17 @@ + + + + + sale.line.pack.line.tree + sale.order.line.pack.line + + + + + + + + + + + diff --git a/sale_product_pack_assisted/views/sale_order_line_views.xml b/sale_product_pack_assisted/views/sale_order_line_views.xml new file mode 100644 index 00000000..eada985d --- /dev/null +++ b/sale_product_pack_assisted/views/sale_order_line_views.xml @@ -0,0 +1,58 @@ + + + + view.order.line.button + sale.order.line + + +
+
+ +
+ + +
+
+
+ + + + +
+
+ +
+ + diff --git a/sale_product_pack_assisted/views/sale_order_views.xml b/sale_product_pack_assisted/views/sale_order_views.xml new file mode 100644 index 00000000..817c7abd --- /dev/null +++ b/sale_product_pack_assisted/views/sale_order_views.xml @@ -0,0 +1,23 @@ + + + + sale.order.form.inherit + sale.order + + + + + +