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
14 changes: 9 additions & 5 deletions purchase_order_secondary_unit/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=============================
Purchase Order Secondary Unit
=============================
Expand All @@ -17,7 +13,7 @@ Purchase Order Secondary Unit
.. |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/license-AGPL--3-blue.png
.. |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
Expand Down Expand Up @@ -130,6 +126,14 @@ 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-sergio-teruel| image:: https://github.com/sergio-teruel.png?size=40px
:target: https://github.com/sergio-teruel
:alt: sergio-teruel

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-sergio-teruel|

This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/18.0/purchase_order_secondary_unit>`_ 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_secondary_unit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"category": "Purchase",
"website": "https://github.com/OCA/purchase-workflow",
"author": "Tecnativa, Odoo Community Association (OCA)",
"maintainers": ["sergio-teruel"],
"license": "AGPL-3",
"application": False,
"installable": True,
Expand Down
13 changes: 13 additions & 0 deletions purchase_order_secondary_unit/models/product_supplierinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo.tools import float_compare


class ProductSupplierinfo(models.Model):
Expand Down Expand Up @@ -30,8 +31,20 @@ def _compute_secondary_uom_price(self):

@api.onchange("secondary_uom_price")
def _inverse_secondary_uom_price(self):
precision = self.env["decimal.precision"].precision_get("Product Price")
for rec in self:
if rec.secondary_uom_id:
expected_secondary_price = rec.price * rec.secondary_uom_id.factor
if (
rec.price
and float_compare(
rec.secondary_uom_price,
expected_secondary_price,
precision_digits=precision,
)
== 0
):
continue
rec.price = rec.secondary_uom_price / rec.secondary_uom_id.factor

@api.onchange("product_tmpl_id", "product_id")
Expand Down
13 changes: 13 additions & 0 deletions purchase_order_secondary_unit/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo.tools import float_compare


class PurchaseOrder(models.Model):
Expand Down Expand Up @@ -58,8 +59,20 @@ def _compute_secondary_uom_price(self):

@api.onchange("secondary_uom_price")
def _inverse_secondary_uom_price(self):
precision = self.env["decimal.precision"].precision_get("Product Price")
for rec in self:
if rec.secondary_uom_id:
expected_secondary_price = rec.price_unit * rec.secondary_uom_id.factor
if (
rec.price_unit
and float_compare(
rec.secondary_uom_price,
expected_secondary_price,
precision_digits=precision,
)
== 0
):
continue
rec.price_unit = rec.secondary_uom_price / rec.secondary_uom_id.factor

@api.onchange("product_uom")
Expand Down
32 changes: 14 additions & 18 deletions purchase_order_secondary_unit/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Purchase Order Secondary Unit</title>
<style type="text/css">

/*
Expand Down Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="purchase-order-secondary-unit">
<h1 class="title">Purchase Order Secondary Unit</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="purchase-order-secondary-unit">
<h1>Purchase Order Secondary Unit</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:931f6f1aa647d4627f4c32d5a657bb5fcbfef63f595c2c84f0790ff27a44ee7d
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/purchase-workflow/tree/18.0/purchase_order_secondary_unit"><img alt="OCA/purchase-workflow" src="https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/purchase-workflow-18-0/purchase-workflow-18-0-purchase_order_secondary_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/purchase-workflow/tree/18.0/purchase_order_secondary_unit"><img alt="OCA/purchase-workflow" src="https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/purchase-workflow-18-0/purchase-workflow-18-0-purchase_order_secondary_unit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module extends the functionality of purchase orders to allow buy
products in secondary unit of distinct category.</p>
<p>Users can enter quantities and prices in secondary units on purchase
Expand All @@ -398,13 +393,13 @@ <h1>Purchase Order Secondary Unit</h1>
</ul>
</div>
<div class="section" id="configuration">
<h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>For configuration of displaying secondary unit information in purchase
reports and the Purchase Order portal, see the guidelines provided in
product_secondary_unit.</p>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>To use this module you need to:</p>
<ol class="arabic simple">
<li>Go to a <em>Product &gt; General Information tab</em>.</li>
Expand All @@ -426,30 +421,30 @@ <h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
</ul>
</div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h2>
<h1><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h1>
<p>Updating existing vendor pricelist records from purchase order
confirmation does not currently support secondary UOM or secondary UOM
pricing. This is not included in the current scope and may be considered
in future improvements.</p>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/purchase-workflow/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_order_secondary_unit%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-5">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-5">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-6">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-6">Authors</a></h2>
<ul class="simple">
<li>Tecnativa</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-7">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Sergio Teruel</li>
Expand All @@ -466,19 +461,20 @@ <h3><a class="toc-backref" href="#toc-entry-7">Contributors</a></h3>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/sergio-teruel"><img alt="sergio-teruel" src="https://github.com/sergio-teruel.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/18.0/purchase_order_secondary_unit">OCA/purchase-workflow</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
</div>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ def test_supplierinfo_secondary_uom_price_inverse(self):
# secondary_uom_price = 140, factor = 0.7, price = 200
self.assertEqual(self.supplierinfo.price, 200.0)

def test_supplierinfo_keeps_price_when_secondary_price_rounds(self):
secondary_unit = self.env["product.secondary.unit"].create(
{
"name": "unit-900",
"uom_id": self.product_uom_unit.id,
"factor": 0.9,
"product_tmpl_id": self.product.product_tmpl_id.id,
}
)
supplierinfo_form = Form(
self.env["product.supplierinfo"].with_context(
default_product_tmpl_id=self.product.product_tmpl_id.id
)
)
supplierinfo_form.partner_id = self.partner
supplierinfo_form.price = 19.95
supplierinfo_form.secondary_uom_id = secondary_unit
self.assertAlmostEqual(supplierinfo_form.secondary_uom_price, 17.96)
self.assertAlmostEqual(supplierinfo_form.price, 19.95)

def test_supplierinfo_no_secondary_unit(self):
self.supplierinfo.secondary_uom_id = False
self.assertEqual(self.supplierinfo.secondary_uom_price, 0.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,32 @@ def test_purchase_order_secondary_uom_price(self):
# price_unit = 100, factor = 0.7, secondary_uom_price = 70
self.assertEqual(line.secondary_uom_price, 70.0)

def test_purchase_order_keeps_supplier_price_when_secondary_price_rounds(self):
secondary_unit = self.env["product.secondary.unit"].create(
{
"name": "unit-900",
"uom_id": self.product_uom_unit.id,
"factor": 0.9,
"product_tmpl_id": self.product.product_tmpl_id.id,
}
)
self.product.purchase_secondary_uom_id = secondary_unit
self.env["product.supplierinfo"].create(
{
"partner_id": self.partner.id,
"product_tmpl_id": self.product.product_tmpl_id.id,
"price": 19.95,
}
)
purchase_order = Form(self.purchase_order_obj)
purchase_order.partner_id = self.partner
with purchase_order.order_line.new() as line:
line.product_id = self.product
self.assertEqual(line.secondary_uom_qty, 1.0)
self.assertAlmostEqual(line.product_qty, 0.9)
self.assertAlmostEqual(line.secondary_uom_price, 17.96)
self.assertAlmostEqual(line.price_unit, 19.95)

def test_purchase_order_confirm_creates_supplierinfo_with_secondary_uom(self):
new_product = self.env["product.product"].create(
{
Expand Down
Loading