diff --git a/purchase_auto_complete_no_zero/README.rst b/purchase_auto_complete_no_zero/README.rst new file mode 100644 index 00000000000..10a1bb0e5e9 --- /dev/null +++ b/purchase_auto_complete_no_zero/README.rst @@ -0,0 +1,80 @@ +============================== +Purchase auto complete no zero +============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:d2c2da7ca283711149cdd1042ae9907d038308cf1e9a1f8a209fff901ae0dc63 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/purchase-workflow/tree/17.0/purchase_auto_complete_no_zero + :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-17-0/purchase-workflow-17-0-purchase_auto_complete_no_zero + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module ensures that, when creating a vendor bill from a Purchase +Order, invoice lines are only generated for products that have a real, +pending quantity to be invoiced. + +**Table of contents** + +.. 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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Jarsa + +Contributors +------------ + +- `Jarsa `__: + + - Hector Meraz + +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_auto_complete_no_zero/__init__.py b/purchase_auto_complete_no_zero/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/purchase_auto_complete_no_zero/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/purchase_auto_complete_no_zero/__manifest__.py b/purchase_auto_complete_no_zero/__manifest__.py new file mode 100644 index 00000000000..8739acca840 --- /dev/null +++ b/purchase_auto_complete_no_zero/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2025 Jarsa +# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Purchase auto complete no zero", + "summary": "Avoid creating zero-quantity lines when creating a vendor bill.", + "version": "17.0.1.0.0", + "category": "Purchases", + "website": "https://github.com/OCA/purchase-workflow", + "author": "Jarsa, Odoo Community Association (OCA)", + "license": "LGPL-3", + "depends": ["purchase"], + "installable": True, +} diff --git a/purchase_auto_complete_no_zero/models/__init__.py b/purchase_auto_complete_no_zero/models/__init__.py new file mode 100644 index 00000000000..8e072db8f3e --- /dev/null +++ b/purchase_auto_complete_no_zero/models/__init__.py @@ -0,0 +1 @@ +from . import account_invoice diff --git a/purchase_auto_complete_no_zero/models/account_invoice.py b/purchase_auto_complete_no_zero/models/account_invoice.py new file mode 100644 index 00000000000..a2fc18537b1 --- /dev/null +++ b/purchase_auto_complete_no_zero/models/account_invoice.py @@ -0,0 +1,18 @@ +from odoo import api, models + + +class AccountMove(models.Model): + _inherit = "account.move" + + @api.onchange("purchase_vendor_bill_id", "purchase_id") + def _onchange_purchase_auto_complete(self): + res = super()._onchange_purchase_auto_complete() + + lines_to_keep = self.invoice_line_ids.filtered( + lambda line: line.display_type in ("line_section", "line_note") + or (line.quantity > 0 and line.price_unit > 0) + ) + + self.invoice_line_ids = lines_to_keep + + return res diff --git a/purchase_auto_complete_no_zero/pyproject.toml b/purchase_auto_complete_no_zero/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/purchase_auto_complete_no_zero/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/purchase_auto_complete_no_zero/readme/CONTRIBUTORS.md b/purchase_auto_complete_no_zero/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..053acdd29b0 --- /dev/null +++ b/purchase_auto_complete_no_zero/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Jarsa](https://www.jarsa.com): + - Hector Meraz diff --git a/purchase_auto_complete_no_zero/readme/DESCRIPTION.md b/purchase_auto_complete_no_zero/readme/DESCRIPTION.md new file mode 100644 index 00000000000..bd6daf1ccb1 --- /dev/null +++ b/purchase_auto_complete_no_zero/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module ensures that, when creating a vendor bill from a Purchase Order, invoice lines are only generated for products that have a real, pending quantity to be invoiced. \ No newline at end of file diff --git a/purchase_auto_complete_no_zero/static/description/index.html b/purchase_auto_complete_no_zero/static/description/index.html new file mode 100644 index 00000000000..e3cc09efbd9 --- /dev/null +++ b/purchase_auto_complete_no_zero/static/description/index.html @@ -0,0 +1,428 @@ + + + + + +Purchase auto complete no zero + + + +
+

Purchase auto complete no zero

+ + +

Beta License: LGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runboat

+

This module ensures that, when creating a vendor bill from a Purchase +Order, invoice lines are only generated for products that have a real, +pending quantity to be invoiced.

+

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 to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Jarsa
  • +
+
+
+

Contributors

+
    +
  • Jarsa:
      +
    • Hector Meraz
    • +
    +
  • +
+
+
+

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_product_code_remove/README.rst b/purchase_product_code_remove/README.rst new file mode 100644 index 00000000000..05b8ca058b9 --- /dev/null +++ b/purchase_product_code_remove/README.rst @@ -0,0 +1,83 @@ +============================ +Purchase Product Code Remove +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:39878a898c0136193be6bf53b69dad594f0dc42c62656a2591f1f2ebe8cc0fd9 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/purchase-workflow/tree/17.0/purchase_product_code_remove + :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-17-0/purchase-workflow-17-0-purchase_product_code_remove + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Removes default code brackets from the beginning of purchase order line +description. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Add a product in the purchase order line, then the description of the +product will be displayed without the default code. + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Jarsa + +Contributors +------------ + +- Alan Ramos + +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_product_code_remove/__init__.py b/purchase_product_code_remove/__init__.py new file mode 100644 index 00000000000..af0b5c22add --- /dev/null +++ b/purchase_product_code_remove/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2023 Jarsa, () +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.html). + +from . import models diff --git a/purchase_product_code_remove/__manifest__.py b/purchase_product_code_remove/__manifest__.py new file mode 100644 index 00000000000..81402e32b18 --- /dev/null +++ b/purchase_product_code_remove/__manifest__.py @@ -0,0 +1,12 @@ +# Copyright 2023 Jarsa, () +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.html). +{ + "name": "Purchase Product Code Remove", + "summary": "Remove product code from purchase order lines description", + "author": "Jarsa, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/purchase-workflow", + "category": "Purchase Management", + "version": "17.0.1.0.0", + "license": "LGPL-3", + "depends": ["purchase"], +} diff --git a/purchase_product_code_remove/models/__init__.py b/purchase_product_code_remove/models/__init__.py new file mode 100644 index 00000000000..bf04c25ea37 --- /dev/null +++ b/purchase_product_code_remove/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2023 Jarsa, () +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.html). + +from . import purchase_order_line diff --git a/purchase_product_code_remove/models/purchase_order_line.py b/purchase_product_code_remove/models/purchase_order_line.py new file mode 100644 index 00000000000..65283756b5a --- /dev/null +++ b/purchase_product_code_remove/models/purchase_order_line.py @@ -0,0 +1,14 @@ +# Copyright 2023 Jarsa, () +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.html). + +from odoo import models + + +class PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + + def _get_product_purchase_description(self, product_lang): + name = super()._get_product_purchase_description(product_lang) + if self.product_id.default_code: + name = name.replace(f"[{self.product_id.default_code}] ", "").strip() + return name diff --git a/purchase_product_code_remove/pyproject.toml b/purchase_product_code_remove/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/purchase_product_code_remove/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/purchase_product_code_remove/readme/CONTRIBUTORS.md b/purchase_product_code_remove/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..4d45c3a1354 --- /dev/null +++ b/purchase_product_code_remove/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Alan Ramos \<\> diff --git a/purchase_product_code_remove/readme/DESCRIPTION.md b/purchase_product_code_remove/readme/DESCRIPTION.md new file mode 100644 index 00000000000..ae1b623eed1 --- /dev/null +++ b/purchase_product_code_remove/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +Removes default code brackets from the beginning of purchase order line +description. diff --git a/purchase_product_code_remove/readme/USAGE.md b/purchase_product_code_remove/readme/USAGE.md new file mode 100644 index 00000000000..207a7116bc4 --- /dev/null +++ b/purchase_product_code_remove/readme/USAGE.md @@ -0,0 +1,2 @@ +Add a product in the purchase order line, then the description of the +product will be displayed without the default code. diff --git a/purchase_product_code_remove/static/description/index.html b/purchase_product_code_remove/static/description/index.html new file mode 100644 index 00000000000..431ceccb5c4 --- /dev/null +++ b/purchase_product_code_remove/static/description/index.html @@ -0,0 +1,430 @@ + + + + + +Purchase Product Code Remove + + + +
+

Purchase Product Code Remove

+ + +

Beta License: LGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runboat

+

Removes default code brackets from the beginning of purchase order line +description.

+

Table of contents

+ +
+

Usage

+

Add a product in the purchase order line, then the description of the +product will be displayed without the default code.

+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Jarsa
  • +
+
+
+

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_request/models/purchase_order.py b/purchase_request/models/purchase_order.py index 87e7a53fca4..14ad050d46f 100644 --- a/purchase_request/models/purchase_order.py +++ b/purchase_request/models/purchase_order.py @@ -10,6 +10,54 @@ class PurchaseOrder(models.Model): _inherit = "purchase.order" + purchase_request_count = fields.Integer( + compute="_compute_purchase_request_count", + default=0, + ) + purchase_request_line_count = fields.Integer( + compute="_compute_purchase_request_line_count", + default=0, + ) + + @api.depends("order_line.purchase_request_lines") + def _compute_purchase_request_count(self): + for order in self: + order.purchase_request_count = len( + order.order_line.mapped("purchase_request_lines.request_id") + ) + + @api.depends("order_line.purchase_request_lines") + def _compute_purchase_request_line_count(self): + for order in self: + order.purchase_request_line_count = len( + order.order_line.mapped("purchase_request_lines") + ) + + def action_open_purchase_request(self): + self.ensure_one() + requests = self.order_line.mapped("purchase_request_lines.request_id") + action = self.env["ir.actions.act_window"]._for_xml_id( + "purchase_request.purchase_request_form_action" + ) + action["context"] = {} + if len(requests) == 1: + action.update({ + "res_id": requests.id, + "views": [(False, "form")], + }) + else: + action["domain"] = [("id", "in", requests.ids)] + return action + + def action_open_purchase_request_lines(self): + self.ensure_one() + request_line_ids = self.order_line.mapped("purchase_request_lines").ids + action = self.env["ir.actions.act_window"]._for_xml_id( + "purchase_request.purchase_request_line_form_action" + ) + action["domain"] = [("id", "in", request_line_ids)] + return action + def _purchase_request_confirm_message_content(self, request, request_dict=None): self.ensure_one() if not request_dict: @@ -64,7 +112,7 @@ def _purchase_request_confirm_message(self): ) request.message_post( body=message, - subtype_id=self.env.ref("mail.mt_note").id, + subtype_id=self.env.ref("mail.mt_comment").id, ) return True @@ -185,7 +233,7 @@ def update_service_allocations(self, prev_qty_received): ) alloc.purchase_request_line_id.request_id.message_post( body=message, - subtype_id=self.env.ref("mail.mt_note").id, + subtype_id=self.env.ref("mail.mt_comment").id, ) alloc.purchase_request_line_id._compute_qty() @@ -241,3 +289,20 @@ def write(self, vals): for line in service_lines: line.update_service_allocations(prev_qty_received[line.id]) return res + + @api.constrains("product_id", "purchase_request_lines") + def _check_product_from_request(self): + errors = [] + for line in self: + for request_line in line.purchase_request_lines: + if request_line.product_id != line.product_id: + errors.append( + _( + "The product %(product_name)s in the Purchase Order Line " + "must be the same as the product in the Purchase Request " + "Line.", + product_name=line.product_id.display_name, + ) + ) + if errors: + raise exceptions.ValidationError("\n".join(errors)) diff --git a/purchase_request/models/purchase_request_allocation.py b/purchase_request/models/purchase_request_allocation.py index c5960627a61..e414abbc647 100644 --- a/purchase_request/models/purchase_request_allocation.py +++ b/purchase_request/models/purchase_request_allocation.py @@ -85,7 +85,7 @@ class PurchaseRequestAllocation(models.Model): ) def _compute_open_product_qty(self): for rec in self: - if rec.purchase_state in ["cancel", "done"]: + if rec.purchase_state == "cancel": rec.open_product_qty = 0.0 else: rec.open_product_qty = ( @@ -132,5 +132,5 @@ def _notify_allocation(self, allocated_qty): message = self._purchase_request_confirm_done_message_content(message_data) request.message_post( body=message, - subtype_id=self.env.ref("mail.mt_note").id, + subtype_id=self.env.ref("mail.mt_comment").id, ) diff --git a/purchase_request/views/purchase_order_view.xml b/purchase_request/views/purchase_order_view.xml index 35c5610f771..de8bb8daf80 100644 --- a/purchase_request/views/purchase_order_view.xml +++ b/purchase_request/views/purchase_order_view.xml @@ -7,6 +7,18 @@ purchase.order + + + +