Skip to content
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
98 changes: 98 additions & 0 deletions sale_purchase_secondary_unit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
============================
Sale Purchase Secondary Unit
============================

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

.. |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/sale_purchase_secondary_unit
: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-sale_purchase_secondary_unit
: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 sale_order_secondary_unit
module and purchase_order_secondary_unit to allow copy secondary uom
from sale orders to purchase orders when a sale order is confirmed.

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module you need to:

1. Go to a *Product > General Information tab*.
2. Create any record in "Secondary unit of measure".
3. Set the conversion factor.
4. Set a product with a buy rule + mto rule
5. Set vendors on product
6. Go to *Sales > orders* and create a sale order with this product and
any second unit.
7. Confirm the sale order.
8. Go to purchaser order created and you will see the second unit in
purchase order line.

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:%20sale_purchase_secondary_unit%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>`__:

- Sergio Teruel
- Carlos Dauden
- Carlos Roca

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 <https://github.com/OCA/purchase-workflow/tree/18.0/sale_purchase_secondary_unit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions sale_purchase_secondary_unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from . import models
20 changes: 20 additions & 0 deletions sale_purchase_secondary_unit/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 Tecnativa - Sergio Teruel
# Copyright 2023 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
{
"name": "Sale Purchase Secondary Unit",
"summary": "Propagate sale secondary uom to purchase orders",
"version": "18.0.1.0.0",
"development_status": "Beta",
"category": "stock",
"website": "https://github.com/OCA/purchase-workflow",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": [
"sale_purchase_stock",
"purchase_order_secondary_unit",
"sale_stock_secondary_unit",
],
"auto_install": True,
}
38 changes: 38 additions & 0 deletions sale_purchase_secondary_unit/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_purchase_secondary_unit
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-11-15 21:38+0000\n"
"Last-Translator: Ivorra78 <[email protected]>\n"
"Language-Team: none\n"
"Language: es\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: sale_purchase_secondary_unit
#: model:ir.model,name:sale_purchase_secondary_unit.model_purchase_order_line
msgid "Purchase Order Line"
msgstr "Línea de Orden de Compra"

#. module: sale_purchase_secondary_unit
#: model:ir.model,name:sale_purchase_secondary_unit.model_sale_order
msgid "Sales Order"
msgstr "Orden de Venta"

#. module: sale_purchase_secondary_unit
#: model:ir.model,name:sale_purchase_secondary_unit.model_stock_rule
msgid "Stock Rule"
msgstr "Regla de Existencias"

#~ msgid "Sales Order Line"
#~ msgstr "Línea de la Orden de Venta"

#~ msgid "Stock Move"
#~ msgstr "Movimiento de Existencias"
29 changes: 29 additions & 0 deletions sale_purchase_secondary_unit/i18n/sale_purchase_secondary_unit.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_purchase_secondary_unit
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.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: sale_purchase_secondary_unit
#: model:ir.model,name:sale_purchase_secondary_unit.model_purchase_order_line
msgid "Purchase Order Line"
msgstr ""

#. module: sale_purchase_secondary_unit
#: model:ir.model,name:sale_purchase_secondary_unit.model_sale_order
msgid "Sales Order"
msgstr ""

#. module: sale_purchase_secondary_unit
#: model:ir.model,name:sale_purchase_secondary_unit.model_stock_rule
msgid "Stock Rule"
msgstr ""
6 changes: 6 additions & 0 deletions sale_purchase_secondary_unit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright 2023 Tecnativa - Sergio Teruel
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from . import purchase_order_line
from . import sale_order
from . import stock_rule
62 changes: 62 additions & 0 deletions sale_purchase_secondary_unit/models/purchase_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2023 Tecnativa - Carlos Dauden
# Copyright 2023 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

from odoo import api, models


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

def _find_candidate(
self,
product_id,
product_qty,
product_uom,
location_id,
name,
origin,
company_id,
values,
):
secondary_uom_id = values.get("secondary_uom_id", False)
po_lines = self.filtered(
lambda x, sec_uom_id=secondary_uom_id: x.secondary_uom_id.id == sec_uom_id
)
return super(PurchaseOrderLine, po_lines)._find_candidate(
product_id,
product_qty,
product_uom,
location_id,
name,
origin,
company_id,
values,
)

@api.model
def _prepare_purchase_order_line_from_procurement(
self,
product_id,
product_qty,
product_uom,
location_dest_id,
name,
origin,
company_id,
values,
po,
):
res = super()._prepare_purchase_order_line_from_procurement(
product_id,
product_qty,
product_uom,
location_dest_id,
name,
origin,
company_id,
values,
po,
)
res["secondary_uom_id"] = values.get("secondary_uom_id", False)
return res
16 changes: 16 additions & 0 deletions sale_purchase_secondary_unit/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 Tecnativa - Carlos Dauden
# Copyright 2023 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

from odoo import models


class SaleOrder(models.Model):
_inherit = "sale.order"

def action_cancel(self):
# When a SO linked to a purchase order is cancelled we must update the
# secondary_uom_qty on po line
return super(
SaleOrder, self.with_context(cancelled_so_lines=self.order_line.ids)
).action_cancel()
70 changes: 70 additions & 0 deletions sale_purchase_secondary_unit/models/stock_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2023 Tecnativa - Sergio Teruel
# Copyright 2023 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)

from odoo import api, models


class StockRule(models.Model):
_inherit = "stock.rule"

@api.model
def _get_procurements_to_merge_groupby(self, procurement):
"""Do not group purchase order line if they have different secondary_uom in
sale order line.
"""
return (
procurement.values.get("secondary_uom_id"),
super()._get_procurements_to_merge_groupby(procurement),
)

@api.model
def _run_buy(self, procurements):
return super(
StockRule, self.with_context(skip_default_secondary_uom_qty=True)
)._run_buy(procurements)

def _update_purchase_order_line(
self, product_id, product_qty, product_uom, company_id, values, line
):
vals = super()._update_purchase_order_line(
product_id, product_qty, product_uom, company_id, values, line
)
if values.get("secondary_uom_id", False):
moves_dest = line.move_dest_ids + values.get(
"move_dest_ids", self.env["stock.move"]
)
moves = self.env["stock.move"].browse(list(moves_dest._rollup_move_dests()))
cancelled_so_lines = self.env.context.get("cancelled_so_lines", [])
sale_lines = moves.mapped("sale_line_id").filtered(
lambda ln: ln.id not in cancelled_so_lines
)
vals["secondary_uom_qty"] = sum(sale_lines.mapped("secondary_uom_qty"))
return vals

@api.model
def get_stock_move_sale_line(self, stock_move):
for move in stock_move.move_dest_ids:
if move.sale_line_id:
return move.sale_line_id
return self.get_stock_move_sale_line(move)

@api.model
def _merge_procurements(self, procurements_to_merge):
# The quantity accumulation is embedded in this method and is not heritable
# Avoid process only one procurement
if len(procurements_to_merge) == 1 and len(procurements_to_merge[0]) == 1:
return super()._merge_procurements(procurements_to_merge)
secondary_index_dic = {}
# Fill dict with total secondary_uom_qty by group of procurements to merge
for index, procurements in enumerate(procurements_to_merge):
secondary_index_dic[index] = 0
for procurement in procurements:
secondary_index_dic[index] += procurement.values.get(
"secondary_uom_qty", 0
)
merged_procurements = super()._merge_procurements(procurements_to_merge)
# Set total secondary_uom_qty from previous dict
for index, merged_procurement in enumerate(merged_procurements):
merged_procurement.values["secondary_uom_qty"] = secondary_index_dic[index]
return merged_procurements
3 changes: 3 additions & 0 deletions sale_purchase_secondary_unit/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 sale_purchase_secondary_unit/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- [Tecnativa](https://www.tecnativa.com):

> - Sergio Teruel
> - Carlos Dauden
> - Carlos Roca
3 changes: 3 additions & 0 deletions sale_purchase_secondary_unit/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module extends the functionality of sale_order_secondary_unit
module and purchase_order_secondary_unit to allow copy secondary uom
from sale orders to purchase orders when a sale order is confirmed.
12 changes: 12 additions & 0 deletions sale_purchase_secondary_unit/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 a *Product \> General Information tab*.
2. Create any record in "Secondary unit of measure".
3. Set the conversion factor.
4. Set a product with a buy rule + mto rule
5. Set vendors on product
6. Go to *Sales \> orders* and create a sale order with this product
and any second unit.
7. Confirm the sale order.
8. Go to purchaser order created and you will see the second unit in
purchase order line.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading