Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0][MIG] purchase_order_supplierinfo_update: Migration to 18.0 #2500

Open
wants to merge 17 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions purchase_order_line_menu/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ Authors
Contributors
------------

- \`Open Source Integrators <https://opensourceintegrators.com>\`:
- \`Open Source Integrators <https://opensourceintegrators.com>\`:

- Daniel Reis <[email protected]>
- Freni Patel <[email protected]>
- Murtaza Mithaiwala <[email protected]>
- \`Moduon Team <https://moduon.team>\`:
- Daniel Reis <[email protected]>
- Freni Patel <[email protected]>
- Murtaza Mithaiwala <[email protected]>
- \`Moduon Team <https://moduon.team>\`:

- Eduardo de Miguel <[email protected]>
- Emilio Pascual <[email protected]>
- Rafael Blasco <[email protected]>
- Eduardo de Miguel <[email protected]>
- Emilio Pascual <[email protected]>
- Rafael Blasco <[email protected]>

Maintainers
-----------
Expand Down
116 changes: 116 additions & 0 deletions purchase_order_supplierinfo_update/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
==================================
Purchase Order Supplierinfo Update
==================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:92abe86bee38e5e3e4496f3de3c026314327701e467c7668dcc55419cc94c7e5
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/18.0/purchase_order_supplierinfo_update
: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-18-0/purchase-workflow-18-0-purchase_order_supplierinfo_update
: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=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the functionality of purchase to allow the price of
the supplier-info to be updated automatically for each product of the a
purchase when it is confirmed. This will allow that when a purchase
order is created, the suggested price for those products is the last one
purchased.

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, you need to:

1. Go to *Purchase > Orders > Requests for Quotation* and create a new
Requests for Quotation with several products.
2. Confirm that quotation and the unit prices defined on the lines will
be stored in the supplier-info (related to the quotation supplier) of
the products.
3. By default the suggested price for the products is the one stored in
supplier-info, so in this way, if you create another quotation with
the same supplier and the same products, the suggested price for each
product will be the same price at which the product was last
purchased.

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

- Refactor that module to share algorithm with similar module
account_invoice_supplierinfo_update.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/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 <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_order_supplierinfo_update%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Tecnativa

Contributors
------------

- `Tecnativa <https://www.tecnativa.com>`__:

- Ernesto Tejeda
- Carlos Dauden

- Daniel Reis <[email protected]>, `Open Source
Integrators <https://www.opensourceintegrators.eu>`__:

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 <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ernestotejeda|

This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/18.0/purchase_order_supplierinfo_update>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions purchase_order_supplierinfo_update/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions purchase_order_supplierinfo_update/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2021 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Purchase Order Supplierinfo Update",
"summary": "Update product supplierinfo with the last purchase price",
"version": "18.0.1.0.0",
"category": "Purchase",
"website": "https://github.com/OCA/purchase-workflow",
"author": "Tecnativa, Odoo Community Association (OCA)",
"maintainers": ["ernestotejeda"],
"license": "AGPL-3",
"depends": ["purchase"],
}
27 changes: 27 additions & 0 deletions purchase_order_supplierinfo_update/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * purchase_order_supplierinfo_update
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-12-24 15:34+0000\n"
"Last-Translator: mymage <[email protected]>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: purchase_order_supplierinfo_update
#: model:ir.model,name:purchase_order_supplierinfo_update.model_purchase_order
msgid "Purchase Order"
msgstr "Ordine di acquisto"

#. module: purchase_order_supplierinfo_update
#: model:ir.model,name:purchase_order_supplierinfo_update.model_purchase_order_line
msgid "Purchase Order Line"
msgstr "Riga ordine di acquisto"
27 changes: 27 additions & 0 deletions purchase_order_supplierinfo_update/i18n/pt_BR.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * purchase_order_supplierinfo_update
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-10-23 14:32+0000\n"
"Last-Translator: Adriano Prado <[email protected]>\n"
"Language-Team: none\n"
"Language: pt_BR\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n > 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: purchase_order_supplierinfo_update
#: model:ir.model,name:purchase_order_supplierinfo_update.model_purchase_order
msgid "Purchase Order"
msgstr "Pedido de Compra"

#. module: purchase_order_supplierinfo_update
#: model:ir.model,name:purchase_order_supplierinfo_update.model_purchase_order_line
msgid "Purchase Order Line"
msgstr "Linha Pedido de Compra"
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * purchase_order_supplierinfo_update
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.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_supplierinfo_update
#: model:ir.model,name:purchase_order_supplierinfo_update.model_purchase_order
msgid "Purchase Order"
msgstr ""

#. module: purchase_order_supplierinfo_update
#: model:ir.model,name:purchase_order_supplierinfo_update.model_purchase_order_line
msgid "Purchase Order Line"
msgstr ""
2 changes: 2 additions & 0 deletions purchase_order_supplierinfo_update/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import purchase_order
72 changes: 72 additions & 0 deletions purchase_order_supplierinfo_update/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2021 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class PurchaseOrder(models.Model):
_inherit = "purchase.order"

def write(self, vals):
no_updated = self.filtered(lambda r: r.state not in ["purchase", "done"])
res = super().write(vals)
if vals.get("state", "") in ["purchase", "done"]:
no_updated.mapped("order_line").update_supplierinfo_price()
return res


class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"

@api.model_create_multi
def create(self, vals_list):
res = super().create(vals_list)
res.update_supplierinfo_price()
return res

def write(self, vals):
res = super().write(vals)
if vals.get("price_unit"):
self.update_supplierinfo_price()
return res

def update_supplierinfo_price(self):
for line in self.filtered(
lambda r: not r.display_type and r.order_id.state in ["purchase", "done"]
):
domain = [
("partner_id", "=", line.partner_id.id),
("product_id", "=", line.product_id.id),
("date_order", ">", line.date_order),
]
if not self.env["purchase.order.line"].search(domain, limit=1):
params = {"order_id": line.order_id}
seller = line.product_id._select_seller(
partner_id=line.partner_id,
quantity=line.product_qty,
date=line.order_id.date_order and line.order_id.date_order.date(),
uom_id=line.product_uom,
params=params,
)
if seller:
line._update_supplierinfo(seller)

def _update_supplierinfo(self, seller):
self.ensure_one()
new_seller_price = self.price_unit
# convert according to the currency if necessary
if self.currency_id and self.currency_id != seller.currency_id:
new_seller_price = self.currency_id._convert(

Check warning on line 59 in purchase_order_supplierinfo_update/models/purchase_order.py

View check run for this annotation

Codecov / codecov/patch

purchase_order_supplierinfo_update/models/purchase_order.py#L59

Added line #L59 was not covered by tests
new_seller_price,
seller.currency_id,
seller.company_id,
self.date_order or fields.Date.today(),
)
# convert according to the UoM if necessary
if self.product_uom and self.product_uom != seller.product_uom:
new_seller_price = self.product_uom._compute_price(

Check warning on line 67 in purchase_order_supplierinfo_update/models/purchase_order.py

View check run for this annotation

Codecov / codecov/patch

purchase_order_supplierinfo_update/models/purchase_order.py#L67

Added line #L67 was not covered by tests
new_seller_price, seller.product_uom
)
# Set price
if new_seller_price != seller.price:
seller.sudo().price = new_seller_price
3 changes: 3 additions & 0 deletions purchase_order_supplierinfo_update/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
5 changes: 5 additions & 0 deletions purchase_order_supplierinfo_update/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- [Tecnativa](https://www.tecnativa.com):
- Ernesto Tejeda
- Carlos Dauden
- Daniel Reis \<<[email protected]>\>, [Open Source
Integrators](https://www.opensourceintegrators.eu):
5 changes: 5 additions & 0 deletions purchase_order_supplierinfo_update/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This module extends the functionality of purchase to allow the price of
the supplier-info to be updated automatically for each product of the a
purchase when it is confirmed. This will allow that when a purchase
order is created, the suggested price for those products is the last one
purchased.
2 changes: 2 additions & 0 deletions purchase_order_supplierinfo_update/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Refactor that module to share algorithm with similar module
account_invoice_supplierinfo_update.
12 changes: 12 additions & 0 deletions purchase_order_supplierinfo_update/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
To use this module, you need to:

1. Go to *Purchase \> Orders \> Requests for Quotation* and create a
new Requests for Quotation with several products.
2. Confirm that quotation and the unit prices defined on the lines will
be stored in the supplier-info (related to the quotation supplier)
of the products.
3. By default the suggested price for the products is the one stored in
supplier-info, so in this way, if you create another quotation with
the same supplier and the same products, the suggested price for
each product will be the same price at which the product was last
purchased.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading