diff --git a/purchase_order_general_discount/README.rst b/purchase_order_general_discount/README.rst new file mode 100644 index 00000000000..8d530815245 --- /dev/null +++ b/purchase_order_general_discount/README.rst @@ -0,0 +1,120 @@ +=============================== +Purchase Order General Discount +=============================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fpurchase--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/purchase-workflow/tree/11.0/purchase_order_general_discount + :alt: OCA/purchase-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/purchase-workflow-11-0/purchase-workflow-11-0-purchase_order_general_discount + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/142/11.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to set a general discount in a purchase order. This general +discount is applied to each line order. + +You can also set a default general discount on suppliers and configure to wich +line field the discount will be applied. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +You can set in settings another discount field to be applied. +For example, if we had `purchase_triple_discount`, we could set the general +discount in discount3 to be applied after all other discounts. + +To do so: + +#. Go to *Purchases > Configuration > Settings* and *Purchase Discount Field* +#. Select the discount you'd wish to use. `purchase_triple_discount` fields + will appear when the module is installed. + +There's a method at `res.company` called `_get_purchase_discount_fields` that +can be used to extend more line discount fields. For example, if we had the +field `discount4`, we could extend it like this: + +.. code-block:: python + + @api.model + def _get_purchase_discount_fields(self): + discount_fields = super()._get_purchase_discount_fields() + discount_fields += [('discount4', _('Discount 4'))] + return discount_fields + +Usage +===== + +To set a partner default general discount you need to: + +#. Go to a partner and set the general discount in *Sales & Purchases* tab. + +To set a general discount in a purchase order you need to: + +#. Create a purchase order. +#. Either select a partner with a purchase general discount defined or set one + in the summary section of the order. +#. This discount will be applied to every line. + +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 +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * David Vidal + * Pedro M. Baeza + * Rafael Blasco + +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. + +This module is part of the `OCA/purchase-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_order_general_discount/__init__.py b/purchase_order_general_discount/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/purchase_order_general_discount/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/purchase_order_general_discount/__manifest__.py b/purchase_order_general_discount/__manifest__.py new file mode 100644 index 00000000000..409f62900c7 --- /dev/null +++ b/purchase_order_general_discount/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2019 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + 'name': 'Purchase Order General Discount', + 'summary': 'General discount per purchase order', + 'version': '11.0.1.0.0', + 'category': 'Purchases', + 'website': 'https://github.com/OCA/purchase-workflow', + 'author': 'Tecnativa, ' + 'Odoo Community Association (OCA)', + 'license': 'AGPL-3', + 'application': False, + 'installable': True, + 'depends': [ + 'purchase_discount', + ], + 'data': [ + 'views/purchase_order_view.xml', + 'views/res_partner_view.xml', + 'views/res_config_view.xml', + ], +} diff --git a/purchase_order_general_discount/i18n/es.po b/purchase_order_general_discount/i18n/es.po new file mode 100644 index 00000000000..a4aebf055be --- /dev/null +++ b/purchase_order_general_discount/i18n/es.po @@ -0,0 +1,107 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_general_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-08-28 12:50+0000\n" +"PO-Revision-Date: 2019-08-28 12:50+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: purchase_order_general_discount +#: model:ir.ui.view,arch_db:purchase_order_general_discount.res_config_settings_view_form_purchase +msgid "" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_company +msgid "Companies" +msgstr "Compañías" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: purchase_order_general_discount +#: code:addons/purchase_order_general_discount/models/res_company.py:22 +#, python-format +msgid "Discount" +msgstr "Descuento" + +#. module: purchase_order_general_discount +#: code:addons/purchase_order_general_discount/models/res_company.py:27 +#, python-format +msgid "Discount 2" +msgstr "Descuento 2" + +#. module: purchase_order_general_discount +#: code:addons/purchase_order_general_discount/models/res_company.py:28 +#, python-format +msgid "Discount 3" +msgstr "Descuento 3" + +#. module: purchase_order_general_discount +#: sql_constraint:purchase.order:0 +msgid "Discount must be lower than 100%." +msgstr "El descuento debe ser menor del 100%." + +#. module: purchase_order_general_discount +#: model:ir.ui.view,arch_db:purchase_order_general_discount.res_config_settings_view_form_purchase +msgid "Field" +msgstr "Campo" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_purchase_order_general_discount +msgid "Gen. Disc. (%)" +msgstr "Desc. Gen. (%)" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_company_purchase_general_discount_field +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_config_settings_purchase_general_discount_field +msgid "Purchase Discount Field" +msgstr "Campo para Descuento General de compra" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_partner_purchase_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_users_purchase_general_discount +msgid "Purchase General Discount (%)" +msgstr "Descuento General de Compra (%)" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_purchase_order +msgid "Purchase Order" +msgstr "Pedido de compra" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_purchase_order_line +msgid "Purchase Order Line" +msgstr "Línea de pedido de compra" + +#. module: purchase_order_general_discount +#: model:ir.ui.view,arch_db:purchase_order_general_discount.res_config_settings_view_form_purchase +msgid "Select to which purchase line field will the purchase general discount be propagated." +msgstr "Escoja a qué campo del descuento de la línea de pedido se propagará el descuento general." + +#. module: purchase_order_general_discount +#: model:ir.model.fields,help:purchase_order_general_discount.field_res_company_purchase_general_discount_field +#: model:ir.model.fields,help:purchase_order_general_discount.field_res_config_settings_purchase_general_discount_field +msgid "Set the purchase line discount field in wich the discounts will be applied." +msgstr "Establecer el campo de descuento de la línea de pedido en el que se aplicará el descuento." + +#. module: purchase_order_general_discount +#: model:ir.ui.view,arch_db:purchase_order_general_discount.purchase_order_form +msgid "Update general discounts" +msgstr "Actualizar descuento general" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_config_settings +msgid "res.config.settings" +msgstr "res.config.settings" diff --git a/purchase_order_general_discount/i18n/purchase_order_general_discount.pot b/purchase_order_general_discount/i18n/purchase_order_general_discount.pot new file mode 100644 index 00000000000..960a61de366 --- /dev/null +++ b/purchase_order_general_discount/i18n/purchase_order_general_discount.pot @@ -0,0 +1,101 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_general_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \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: purchase_order_general_discount +#: model:ir.ui.view,arch_db:purchase_order_general_discount.res_config_settings_view_form_purchase +msgid "" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_company +msgid "Companies" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_partner +msgid "Contact" +msgstr "" + +#. module: purchase_order_general_discount +#: code:addons/purchase_order_general_discount/models/res_company.py:22 +#, python-format +msgid "Discount" +msgstr "" + +#. module: purchase_order_general_discount +#: code:addons/purchase_order_general_discount/models/res_company.py:26 +#, python-format +msgid "Discount 2" +msgstr "" + +#. module: purchase_order_general_discount +#: code:addons/purchase_order_general_discount/models/res_company.py:30 +#, python-format +msgid "Discount 3" +msgstr "" + +#. module: purchase_order_general_discount +#: sql_constraint:purchase.order:0 +msgid "Discount must be lower than 100%." +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.ui.view,arch_db:purchase_order_general_discount.res_config_settings_view_form_purchase +msgid "Field" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_purchase_order_general_discount +msgid "Gen. Disc. (%)" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_company_purchase_general_discount_field +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_config_settings_purchase_general_discount_field +msgid "Purchase Discount Field" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_partner_purchase_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_users_purchase_general_discount +msgid "Purchase General Discount (%)" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_purchase_order +msgid "Purchase Order" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.ui.view,arch_db:purchase_order_general_discount.res_config_settings_view_form_purchase +msgid "Select to which purchase line field will the purchase general discount be propagated." +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,help:purchase_order_general_discount.field_res_company_purchase_general_discount_field +#: model:ir.model.fields,help:purchase_order_general_discount.field_res_config_settings_purchase_general_discount_field +msgid "Set the purchase line discount field in wich the discounts will be applied." +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.ui.view,arch_db:purchase_order_general_discount.purchase_order_form +msgid "Update general discounts" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_config_settings +msgid "res.config.settings" +msgstr "" + diff --git a/purchase_order_general_discount/models/__init__.py b/purchase_order_general_discount/models/__init__.py new file mode 100644 index 00000000000..eba22b70df1 --- /dev/null +++ b/purchase_order_general_discount/models/__init__.py @@ -0,0 +1,4 @@ +from . import purchase_order +from . import res_company +from . import res_config_settings +from . import res_partner diff --git a/purchase_order_general_discount/models/purchase_order.py b/purchase_order_general_discount/models/purchase_order.py new file mode 100644 index 00000000000..01c125e7da6 --- /dev/null +++ b/purchase_order_general_discount/models/purchase_order.py @@ -0,0 +1,73 @@ +# Copyright 2019 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import api, fields, models +from odoo.addons import decimal_precision as dp +from lxml import etree + + +class PurchaseOrder(models.Model): + _inherit = 'purchase.order' + + general_discount = fields.Float( + digits=dp.get_precision('Discount'), + string='Gen. Disc. (%)', + ) + + _sql_constraints = [ + ('general_discount_limit', 'CHECK (general_discount <= 100.0)', + 'Discount must be lower than 100%.'), + ] + + @api.onchange('partner_id') + def onchange_partner_id(self): + super().onchange_partner_id() + self.general_discount = ( + self.partner_id.commercial_partner_id.purchase_general_discount) + + def _get_general_discount_field(self): + """We can set in settings another discount field to be applied + For example, if we had purchase_triple_dicount, we could set the + general discount in discount3 to be applied after all other + discounts""" + discount_field = self.company_id.purchase_general_discount_field + return discount_field or 'discount' + + @api.onchange('general_discount') + def onchange_general_discount(self): + discount_field = self._get_general_discount_field() + self.mapped('order_line').update({ + discount_field: self.general_discount, + }) + + def action_update_general_discount(self): + for order in self: + order.onchange_general_discount() + + @api.model + def fields_view_get(self, view_id=None, view_type='form', toolbar=False, + submenu=False): + """The purpose of this is to write a context on "order_line" field + respecting other contexts on this field. + There is a PR (https://github.com/odoo/odoo/pull/26607) to odoo for + avoiding this. If merged, remove this method and add the attribute + in the field. + """ + res = super().fields_view_get( + view_id=view_id, view_type=view_type, toolbar=toolbar, + submenu=submenu, + ) + if view_type == 'form': + discount_field = self._get_general_discount_field() + order_xml = etree.XML(res['arch']) + order_line_fields = order_xml.xpath("//field[@name='order_line']") + if order_line_fields: + order_line_field = order_line_fields[0] + context = order_line_field.attrib.get("context", "{}").replace( + "{", + "{{'default_{}': general_discount, ".format( + discount_field), + 1, + ) + order_line_field.attrib['context'] = context + res['arch'] = etree.tostring(order_xml) + return res diff --git a/purchase_order_general_discount/models/res_company.py b/purchase_order_general_discount/models/res_company.py new file mode 100644 index 00000000000..bde95519c1a --- /dev/null +++ b/purchase_order_general_discount/models/res_company.py @@ -0,0 +1,32 @@ +# Copyright 2019 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import _, api, fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + purchase_general_discount_field = fields.Selection( + selection='_get_purchase_discount_fields', + string='Purchase Discount Field', + default='discount', + help='Set the purchase line discount field in wich the ' + 'discounts will be applied.', + ) + + @api.model + def _get_purchase_discount_fields(self): + """Extensible method to add possible discounts. We offer in advance + the posibility of using purchase_triple_discount so no bridge + module is needed """ + discount_fields = [('discount', _('Discount'))] + purchase_line_fields = self.env['purchase.order.line']._fields.keys() + if 'discount2' in purchase_line_fields: + discount_fields += [ + ('discount2', _('Discount 2')), + ] + if 'discount3' in purchase_line_fields: + discount_fields += [ + ('discount3', _('Discount 3')), + ] + return discount_fields diff --git a/purchase_order_general_discount/models/res_config_settings.py b/purchase_order_general_discount/models/res_config_settings.py new file mode 100644 index 00000000000..2f8512d639e --- /dev/null +++ b/purchase_order_general_discount/models/res_config_settings.py @@ -0,0 +1,13 @@ +# Copyright 2019 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + purchase_general_discount_field = fields.Selection( + related='company_id.purchase_general_discount_field', + default='discount', + readonly=False, + ) diff --git a/purchase_order_general_discount/models/res_partner.py b/purchase_order_general_discount/models/res_partner.py new file mode 100644 index 00000000000..68b04b0cd31 --- /dev/null +++ b/purchase_order_general_discount/models/res_partner.py @@ -0,0 +1,15 @@ +# Copyright 2019 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models +from odoo.addons import decimal_precision as dp + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + purchase_general_discount = fields.Float( + digits=dp.get_precision('Discount'), + string='Purchase General Discount (%)', + company_dependent=True, + ) diff --git a/purchase_order_general_discount/readme/CONFIGURE.rst b/purchase_order_general_discount/readme/CONFIGURE.rst new file mode 100644 index 00000000000..db68567f6e1 --- /dev/null +++ b/purchase_order_general_discount/readme/CONFIGURE.rst @@ -0,0 +1,21 @@ +You can set in settings another discount field to be applied. +For example, if we had `purchase_triple_discount`, we could set the general +discount in discount3 to be applied after all other discounts. + +To do so: + +#. Go to *Purchases > Configuration > Settings* and *Purchase Discount Field* +#. Select the discount you'd wish to use. `purchase_triple_discount` fields + will appear when the module is installed. + +There's a method at `res.company` called `_get_purchase_discount_fields` that +can be used to extend more line discount fields. For example, if we had the +field `discount4`, we could extend it like this: + +.. code-block:: python + + @api.model + def _get_purchase_discount_fields(self): + discount_fields = super()._get_purchase_discount_fields() + discount_fields += [('discount4', _('Discount 4'))] + return discount_fields diff --git a/purchase_order_general_discount/readme/CONTRIBUTORS.rst b/purchase_order_general_discount/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..e338bbfbb64 --- /dev/null +++ b/purchase_order_general_discount/readme/CONTRIBUTORS.rst @@ -0,0 +1,5 @@ +* `Tecnativa `_: + + * David Vidal + * Pedro M. Baeza + * Rafael Blasco diff --git a/purchase_order_general_discount/readme/DESCRIPTION.rst b/purchase_order_general_discount/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..f4907d504df --- /dev/null +++ b/purchase_order_general_discount/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +This module allows to set a general discount in a purchase order. This general +discount is applied to each line order. + +You can also set a default general discount on suppliers and configure to wich +line field the discount will be applied. diff --git a/purchase_order_general_discount/readme/USAGE.rst b/purchase_order_general_discount/readme/USAGE.rst new file mode 100644 index 00000000000..6abfbb84d86 --- /dev/null +++ b/purchase_order_general_discount/readme/USAGE.rst @@ -0,0 +1,10 @@ +To set a partner default general discount you need to: + +#. Go to a partner and set the general discount in *Sales & Purchases* tab. + +To set a general discount in a purchase order you need to: + +#. Create a purchase order. +#. Either select a partner with a purchase general discount defined or set one + in the summary section of the order. +#. This discount will be applied to every line. diff --git a/purchase_order_general_discount/static/description/icon.png b/purchase_order_general_discount/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/purchase_order_general_discount/static/description/icon.png differ diff --git a/purchase_order_general_discount/static/description/index.html b/purchase_order_general_discount/static/description/index.html new file mode 100644 index 00000000000..8bd91aa68af --- /dev/null +++ b/purchase_order_general_discount/static/description/index.html @@ -0,0 +1,468 @@ + + + + + + +Purchase Order General Discount + + + +
+

Purchase Order General Discount

+ + +

Beta License: AGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runbot

+

This module allows to set a general discount in a purchase order. This general +discount is applied to each line order.

+

You can also set a default general discount on suppliers and configure to wich +line field the discount will be applied.

+

Table of contents

+ +
+

Configuration

+

You can set in settings another discount field to be applied. +For example, if we had purchase_triple_discount, we could set the general +discount in discount3 to be applied after all other discounts.

+

To do so:

+
    +
  1. Go to Purchases > Configuration > Settings and Purchase Discount Field
  2. +
  3. Select the discount you’d wish to use. purchase_triple_discount fields +will appear when the module is installed.
  4. +
+

There’s a method at res.company called _get_purchase_discount_fields that +can be used to extend more line discount fields. For example, if we had the +field discount4, we could extend it like this:

+
+@api.model
+def _get_purchase_discount_fields(self):
+    discount_fields = super()._get_purchase_discount_fields()
+    discount_fields += [('discount4', _('Discount 4'))]
+    return discount_fields
+
+
+
+

Usage

+

To set a partner default general discount you need to:

+
    +
  1. Go to a partner and set the general discount in Sales & Purchases tab.
  2. +
+

To set a general discount in a purchase order you need to:

+
    +
  1. Create a purchase order.
  2. +
  3. Either select a partner with a purchase general discount defined or set one +in the summary section of the order.
  4. +
  5. This discount will be applied to every line.
  6. +
+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:

    +
    +
      +
    • David Vidal
    • +
    • Pedro M. Baeza
    • +
    • Rafael Blasco
    • +
    +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/purchase-workflow project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/purchase_order_general_discount/tests/__init__.py b/purchase_order_general_discount/tests/__init__.py new file mode 100644 index 00000000000..f51e1fb3d51 --- /dev/null +++ b/purchase_order_general_discount/tests/__init__.py @@ -0,0 +1 @@ +from . import test_purchase_order_general_discount diff --git a/purchase_order_general_discount/tests/test_purchase_order_general_discount.py b/purchase_order_general_discount/tests/test_purchase_order_general_discount.py new file mode 100644 index 00000000000..6bf44e3d672 --- /dev/null +++ b/purchase_order_general_discount/tests/test_purchase_order_general_discount.py @@ -0,0 +1,71 @@ +# Copyright 2019 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests import SavepointCase +from odoo import fields +from lxml import etree + + +class TestPurchaseOrderLineInput(SavepointCase): + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env['res.partner'].create({ + 'name': 'Test', + 'purchase_general_discount': 10.0, + }) + cls.product = cls.env['product.product'].create({ + 'name': 'test_product', + 'type': 'service', + }) + cls.order = cls.env['purchase.order'].create({ + 'partner_id': cls.partner.id, + 'order_line': [(0, 0, { + 'date_planned': fields.Datetime.now(), + 'name': cls.product.name, + 'product_id': cls.product.id, + 'product_qty': 1, + 'product_uom': cls.product.uom_id.id, + 'price_unit': 1000.00, + })], + }) + cls.View = cls.env['ir.ui.view'] + + def test_01_default_partner_discount(self): + self.order.onchange_partner_id() + self.assertEqual(self.order.general_discount, + self.partner.purchase_general_discount) + + def test_02_sale_order_values(self): + self.order.general_discount = 10 + self.order.action_update_general_discount() + self.assertEqual(self.order.order_line.price_subtotal, 900.00) + + def _get_ctx_from_view(self, res): + order_xml = etree.XML(res['arch']) + order_line_path = "//field[@name='order_line']" + order_line_field = order_xml.xpath(order_line_path)[0] + return order_line_field.attrib.get("context", "{}") + + def test_03_default_line_discount_value(self): + res = self.order.fields_view_get( + view_id=self.env.ref('purchase_order_general_discount.' + 'purchase_order_form').id, + view_type='form') + ctx = self._get_ctx_from_view(res) + self.assertTrue('default_discount' in ctx) + view = self.View.create({ + 'name': "test", + 'type': "form", + 'model': 'purchase.order', + 'arch': """ + + + + + """ + }) + res = self.order.fields_view_get(view_id=view.id, view_type='form') + ctx = self._get_ctx_from_view(res) + self.assertTrue('default_discount' in ctx) diff --git a/purchase_order_general_discount/views/purchase_order_view.xml b/purchase_order_general_discount/views/purchase_order_view.xml new file mode 100644 index 00000000000..bea8f7e9a23 --- /dev/null +++ b/purchase_order_general_discount/views/purchase_order_view.xml @@ -0,0 +1,20 @@ + + + + + + purchase.order + + + + + + + + + + diff --git a/purchase_order_general_discount/views/res_config_view.xml b/purchase_order_general_discount/views/res_config_view.xml new file mode 100644 index 00000000000..fe90ea03b99 --- /dev/null +++ b/purchase_order_general_discount/views/res_config_view.xml @@ -0,0 +1,30 @@ + + + + + + res.config.settings + + + +
+
+
+
+
+
+
+ +
diff --git a/purchase_order_general_discount/views/res_partner_view.xml b/purchase_order_general_discount/views/res_partner_view.xml new file mode 100644 index 00000000000..bb844174ce5 --- /dev/null +++ b/purchase_order_general_discount/views/res_partner_view.xml @@ -0,0 +1,17 @@ + + + + + + res.partner + + + + + + + + + diff --git a/setup/_metapackage/VERSION.txt b/setup/_metapackage/VERSION.txt index ed77dfd9b86..8135f518aa2 100644 --- a/setup/_metapackage/VERSION.txt +++ b/setup/_metapackage/VERSION.txt @@ -1 +1 @@ -11.0.20190828.1 \ No newline at end of file +11.0.20190831.0 \ No newline at end of file diff --git a/setup/_metapackage/setup.py b/setup/_metapackage/setup.py index a27a1330e17..a4b1141239d 100644 --- a/setup/_metapackage/setup.py +++ b/setup/_metapackage/setup.py @@ -25,6 +25,7 @@ 'odoo11-addon-purchase_order_approval_block', 'odoo11-addon-purchase_order_approved', 'odoo11-addon-purchase_order_archive', + 'odoo11-addon-purchase_order_general_discount', 'odoo11-addon-purchase_order_line_deep_sort', 'odoo11-addon-purchase_order_line_description', 'odoo11-addon-purchase_order_line_stock_available', diff --git a/setup/purchase_order_general_discount/odoo/addons/purchase_order_general_discount b/setup/purchase_order_general_discount/odoo/addons/purchase_order_general_discount new file mode 120000 index 00000000000..943ff0195ab --- /dev/null +++ b/setup/purchase_order_general_discount/odoo/addons/purchase_order_general_discount @@ -0,0 +1 @@ +../../../../purchase_order_general_discount \ No newline at end of file diff --git a/setup/purchase_order_general_discount/setup.cfg b/setup/purchase_order_general_discount/setup.cfg new file mode 100644 index 00000000000..3c6e79cf31d --- /dev/null +++ b/setup/purchase_order_general_discount/setup.cfg @@ -0,0 +1,2 @@ +[bdist_wheel] +universal=1 diff --git a/setup/purchase_order_general_discount/setup.py b/setup/purchase_order_general_discount/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/purchase_order_general_discount/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)