diff --git a/purchase_allowed_product/README.rst b/purchase_allowed_product/README.rst index 80f888a0647..4b4c6e1abb3 100644 --- a/purchase_allowed_product/README.rst +++ b/purchase_allowed_product/README.rst @@ -1,63 +1,85 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: https://www.gnu.org/licenses/agpl - :alt: License: AGPL-3 - ==================================== Purchase and Invoice Allowed Product ==================================== -This module adds a restriction in purchase and supplier invoices that has the mark "Order and invoice only supplied products" checked for allowing to select only products that can be supplied by the this supplier. +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/12.0/purchase_allowed_product + :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-12-0/purchase-workflow-12-0-purchase_allowed_product + :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/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a restriction in purchase and supplier invoices that has the +mark "Order and invoice only supplied products" checked for allowing to select +only products that can be supplied by the defined vendor. The restriction can be set by default for each partner, and it's propagated -to their supplier invoices and purchase, but it can be change for each invoice and purchase if you want. - -Installation -============ +to their supplier invoices and purchases, but it can be changed for each +invoice and purchase order if you want. -To install this module, you need to: +**Table of contents** -* clone the branch 12.0 of the repository https://github.com/OCA/purchase-workflow -* add the path to this repository in your configuration (addons-path) -* update the module list -* search for "Account Invoice Allowed Product" in your addons -* install the module +.. contents:: + :local: 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. +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 +~~~~~~~ + +* Akretion + Contributors ------------- +~~~~~~~~~~~~ * Chafique Delli * Mourad EL HADJ MIMOUNE * Hieu, Vo Minh Bao - -`Tecnativa `__: +* `Tecnativa `__: * Manuel Calero + * Pedro M. Baeza -Do not contact contributors directly about support or help with technical issues. +Maintainers +~~~~~~~~~~~ -Maintainer ----------- +This module is maintained by the OCA. .. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association :target: https://odoo-community.org -This module is maintained by the OCA. - 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. -To contribute to this module, please visit https://odoo-community.org. +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_allowed_product/__manifest__.py b/purchase_allowed_product/__manifest__.py index 898f8b46b99..0eaf658ace4 100644 --- a/purchase_allowed_product/__manifest__.py +++ b/purchase_allowed_product/__manifest__.py @@ -3,9 +3,9 @@ # 2020 Manuel Calero - Tecnativa # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { - 'name': 'Account Invoice Allowed Product', + 'name': 'Purchase and Invoice Allowed Product', 'summary': 'This module allows to select only products that can be ' - 'supplied by the supplier', + 'supplied by the vendor', 'version': '12.0.1.0.0', 'category': 'Accounting & Finance', 'website': 'https://github.com/OCA/purchase-workflow', diff --git a/purchase_allowed_product/i18n/es.po b/purchase_allowed_product/i18n/es.po index 9b0a42bdfac..7db68b075e4 100644 --- a/purchase_allowed_product/i18n/es.po +++ b/purchase_allowed_product/i18n/es.po @@ -8,15 +8,16 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 12.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-06-01 02:48+0000\n" -"PO-Revision-Date: 2017-06-01 02:48+0000\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: 2020-08-11 15:49+0200\n" "Last-Translator: OCA Transbot , 2017\n" "Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" "Language: es\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" +"Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 2.3\n" #. module: purchase_allowed_product #: model:ir.model,name:purchase_allowed_product.model_res_partner @@ -41,16 +42,18 @@ msgid "" "supplied by this supplier when creating a supplier invoice or purchase for " "it. This value can be changed by invoice or purchase." msgstr "" -"Si está marcada, de forma predeterminada solo podrá seleccionar productos que " -"este proveedor puede suministrar al crear una factura o pedido. Este valor " -"puede modificarse en la factura o en el pedido."" +"Si está marcada, de forma predeterminada solo podrá seleccionar productos " +"que este proveedor puede suministrar al crear una factura o pedido. Este " +"valor puede modificarse en la factura o en el pedido." #. module: purchase_allowed_product #: model:ir.model.fields,help:purchase_allowed_product.field_account_invoice_use_only_supplied_product #: model:ir.model.fields,help:purchase_allowed_product.field_purchase_order_use_only_supplied_product #: model:ir.model.fields,help:purchase_allowed_product.field_supplied_product_mixin_use_only_supplied_product msgid "If checked, only the products provided by this supplier will be shown." -msgstr "Si se marca, solo se mostrarán los productos proporcionados por este proveedor" +msgstr "" +"Si se marca, solo se mostrarán los productos proporcionados por este " +"proveedor." #. module: purchase_allowed_product #: model:ir.model,name:purchase_allowed_product.model_product_supplierinfo @@ -93,4 +96,4 @@ msgstr "Usar solo los productos permitidos" #. module: purchase_allowed_product #: model:ir.model,name:purchase_allowed_product.model_supplied_product_mixin msgid "supplied.product.mixin" -msgstr "" +msgstr "supplied.product.mixin" diff --git a/purchase_allowed_product/models/product.py b/purchase_allowed_product/models/product.py index 6c6ea6194ce..1fe7a6c5395 100644 --- a/purchase_allowed_product/models/product.py +++ b/purchase_allowed_product/models/product.py @@ -1,5 +1,6 @@ -# © 2017 Today Mourad EL HADJ MIMOUNE @ Akretion -# 2020 Manuel Calero - Tecnativa +# Copyright 2017 Today Mourad EL HADJ MIMOUNE @ Akretion +# Copyright 2020 Tecnativa - Manuel Calero +# Copyright 2020 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import api, models @@ -9,32 +10,23 @@ class ProductProduct(models.Model): _inherit = "product.product" @api.model - def search(self, args, offset=0, limit=None, order=None, count=False): + def _search(self, args, offset=0, limit=None, order=None, count=False, + access_rights_uid=None): use_only_supplied_product = self.env.context.get( 'use_only_supplied_product') if use_only_supplied_product: restrict_supplier_id = self.env.context.get('restrict_supplier_id') seller = self.env['res.partner'].browse(restrict_supplier_id) - seller = seller.commercial_partner_id \ - if seller.commercial_partner_id else seller + seller = seller.commercial_partner_id supplierinfos = self.env['product.supplierinfo'].search( [('name', '=', seller.id)]) args += [ '|', ('product_tmpl_id', 'in', - [x.product_tmpl_id.id for x in supplierinfos]), + supplierinfos.mapped('product_tmpl_id').ids), ('id', 'in', - [x.product_id.id for x in supplierinfos])] - - return super(ProductProduct, self).search( - args, offset=offset, limit=limit, order=order, count=count) - - @api.model - def name_search(self, name, args=None, operator='ilike', limit=100): - args = args or [] - if name: - args += [ - ('name', operator, name) + supplierinfos.mapped('product_id').ids) ] - tasks = self.search(args, limit=limit) - return tasks.name_get() + return super()._search( + args, offset=offset, limit=limit, order=order, count=count, + access_rights_uid=access_rights_uid) diff --git a/purchase_allowed_product/models/supplied_product_mixin.py b/purchase_allowed_product/models/supplied_product_mixin.py index 154fd517446..7067c215bba 100644 --- a/purchase_allowed_product/models/supplied_product_mixin.py +++ b/purchase_allowed_product/models/supplied_product_mixin.py @@ -6,6 +6,7 @@ class SuppliedProductMixin(models.AbstractModel): _name = 'supplied.product.mixin' + _description = "Mixin for documents that want to restrict products" use_only_supplied_product = fields.Boolean( string="Use only allowed products", diff --git a/purchase_allowed_product/readme/CONTRIBUTORS.rst b/purchase_allowed_product/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..6e3da03cff0 --- /dev/null +++ b/purchase_allowed_product/readme/CONTRIBUTORS.rst @@ -0,0 +1,7 @@ +* Chafique Delli +* Mourad EL HADJ MIMOUNE +* Hieu, Vo Minh Bao +* `Tecnativa `__: + + * Manuel Calero + * Pedro M. Baeza diff --git a/purchase_allowed_product/readme/DESCRIPTION.rst b/purchase_allowed_product/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..52a2e1decbd --- /dev/null +++ b/purchase_allowed_product/readme/DESCRIPTION.rst @@ -0,0 +1,7 @@ +This module adds a restriction in purchase and supplier invoices that has the +mark "Order and invoice only supplied products" checked for allowing to select +only products that can be supplied by the defined vendor. + +The restriction can be set by default for each partner, and it's propagated +to their supplier invoices and purchases, but it can be changed for each +invoice and purchase order if you want. diff --git a/purchase_allowed_product/static/description/index.html b/purchase_allowed_product/static/description/index.html new file mode 100644 index 00000000000..85c404c3cef --- /dev/null +++ b/purchase_allowed_product/static/description/index.html @@ -0,0 +1,431 @@ + + + + + + +Purchase and Invoice Allowed Product + + + +
+

Purchase and Invoice Allowed Product

+ + +

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

+

This module adds a restriction in purchase and supplier invoices that has the +mark “Order and invoice only supplied products” checked for allowing to select +only products that can be supplied by the defined vendor.

+

The restriction can be set by default for each partner, and it’s propagated +to their supplier invoices and purchases, but it can be changed for each +invoice and purchase order if you want.

+

Table of contents

+ +
+

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

+
    +
  • Akretion
  • +
+
+
+

Contributors

+ +
+
+

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_allowed_product/tests/test_purchase_allowed_product.py b/purchase_allowed_product/tests/test_purchase_allowed_product.py index 714ad86a595..a2e22a07279 100644 --- a/purchase_allowed_product/tests/test_purchase_allowed_product.py +++ b/purchase_allowed_product/tests/test_purchase_allowed_product.py @@ -1,4 +1,5 @@ -# © 2017 Today Mourad EL HADJ MIMOUNE @ Akretion +# Copyright 2017 Today Mourad EL HADJ MIMOUNE @ Akretion +# Copyright 2020 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). @@ -68,8 +69,9 @@ def test_purchase_onchange(self): 'restrict_supplier_id': self.purchase.partner_id.id, 'use_only_supplied_product': self.purchase.use_only_supplied_product} - supplied_product = self.product_model.with_context(context).search([]) - self.assertEqual(supplied_product, self.prtner_4_supplied_products) + supplied_product = self.product_model.with_context(context)._search([]) + self.assertEqual( + set(supplied_product), set(self.prtner_4_supplied_products.ids)) def test_invoice_onchange(self): """A user creates a invoice from the form.""" @@ -88,5 +90,6 @@ def test_invoice_onchange(self): 'restrict_supplier_id': self.invoice.partner_id.id, 'use_only_supplied_product': self.invoice.use_only_supplied_product} - supplied_product = self.product_model.with_context(context).search([]) - self.assertEqual(supplied_product, self.prtner_4_supplied_products) + supplied_product = self.product_model.with_context(context)._search([]) + self.assertEqual( + set(supplied_product), set(self.prtner_4_supplied_products.ids))