Skip to content

Commit

Permalink
Standard migration
Browse files Browse the repository at this point in the history
  • Loading branch information
sa3m authored and ramiadavid committed Oct 19, 2022
1 parent 0142650 commit 3192d33
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 70 deletions.
16 changes: 8 additions & 8 deletions purchase_discount/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Purchase order lines with discounts
: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_discount
:target: https://github.com/OCA/purchase-workflow/tree/13.0/purchase_discount
: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_discount
:target: https://translation.odoo-community.org/projects/purchase-workflow-13-0/purchase-workflow-13-0-purchase_discount
: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
:target: https://runbot.odoo-community.org/runbot/142/13.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -37,20 +37,20 @@ it to purchase order lines:
discounted in price.
* You can set prices and discounts on the same screen.

.. image:: https://raw.githubusercontent.com/OCA/purchase-workflow/12.0/purchase_discount/static/description/product_supplierinfo_form.png
.. image:: https://raw.githubusercontent.com/OCA/purchase-workflow/13.0/purchase_discount/static/description/product_supplierinfo_form.png


* A new field default_supplierinfo_discount is added on res.partner model.
This value will be used as the default one, on each supplierinfo of that
supplier.

.. image:: https://raw.githubusercontent.com/OCA/purchase-workflow/12.0/purchase_discount/static/description/res_partner_company_form.png
.. image:: https://raw.githubusercontent.com/OCA/purchase-workflow/13.0/purchase_discount/static/description/res_partner_company_form.png


Note: this setting is a new 'company' setting, unavailable for related
partners, as accounting-related Settings.

.. image:: https://raw.githubusercontent.com/OCA/purchase-workflow/12.0/purchase_discount/static/description/res_partner_individual_form.png
.. image:: https://raw.githubusercontent.com/OCA/purchase-workflow/13.0/purchase_discount/static/description/res_partner_individual_form.png

**Table of contents**

Expand Down Expand Up @@ -80,7 +80,7 @@ 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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_discount%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_discount%0Aversion:%2013.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.

Expand Down Expand Up @@ -127,6 +127,6 @@ 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/12.0/purchase_discount>`_ project on GitHub.
This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/13.0/purchase_discount>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion purchase_discount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"ACSONE SA/NV,"
"GRAP,"
"Odoo Community Association (OCA)",
"version": "12.0.1.0.2",
"version": "13.0.1.0.0",
"category": "Purchase Management",
"website": "https://github.com/OCA/purchase-workflow",
"depends": ["purchase_stock"],
Expand Down
2 changes: 1 addition & 1 deletion purchase_discount/i18n/purchase_discount.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
Expand Down
1 change: 0 additions & 1 deletion purchase_discount/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from . import account_invoice
from . import purchase_order
from . import stock_move
from . import stock_rule
Expand Down
12 changes: 0 additions & 12 deletions purchase_discount/models/account_invoice.py

This file was deleted.

5 changes: 1 addition & 4 deletions purchase_discount/models/product_supplierinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@

from odoo import api, fields, models

import odoo.addons.decimal_precision as dp


class ProductSupplierInfo(models.Model):
_inherit = "product.supplierinfo"

discount = fields.Float(string="Discount (%)", digits=dp.get_precision("Discount"))
discount = fields.Float(string="Discount (%)", digits="Discount")

@api.onchange("name")
@api.multi
def onchange_name(self):
""" Apply the default supplier discount of the selected supplier """
for supplierinfo in self.filtered("name"):
Expand Down
11 changes: 6 additions & 5 deletions purchase_discount/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@

from odoo import api, fields, models

import odoo.addons.decimal_precision as dp


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

@api.multi
def _add_supplier_to_product(self):
""" Insert a mapping of products to PO lines to be picked up
in supplierinfo's create() """
Expand All @@ -37,7 +34,7 @@ def _prepare_compute_all_values(self):
vals.update({"price_unit": self._get_discounted_price_unit()})
return vals

discount = fields.Float(string="Discount (%)", digits=dp.get_precision("Discount"))
discount = fields.Float(string="Discount (%)", digits="Discount")

_sql_constraints = [
(
Expand All @@ -59,7 +56,6 @@ def _get_discounted_price_unit(self):
return self.price_unit * (1 - self.discount / 100)
return self.price_unit

@api.multi
def _get_stock_move_price_unit(self):
"""Get correct price with discount replacing current price_unit
value before calling super and restoring it later for assuring
Expand Down Expand Up @@ -106,3 +102,8 @@ def _apply_value_from_seller(self, seller):
if not seller:
return
self.discount = seller.discount

def _prepare_account_move_line(self, move):
vals = super(PurchaseOrderLine, self)._prepare_account_move_line(move)
vals["discount"] = self.discount
return vals
4 changes: 1 addition & 3 deletions purchase_discount/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

from odoo import fields, models

from odoo.addons import decimal_precision as dp


class ResPartner(models.Model):
_inherit = "res.partner"

default_supplierinfo_discount = fields.Float(
string="Default Supplier Discount (%)",
digits=dp.get_precision("Discount"),
digits="Discount",
help="This value will be used as the default one, for each new"
" supplierinfo line depending on that supplier.",
)
10 changes: 6 additions & 4 deletions purchase_discount/models/stock_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
class StockRule(models.Model):
_inherit = "stock.rule"

@api.multi
def _prepare_purchase_order_line(
self, product_id, product_qty, product_uom, values, po, partner
self, product_id, product_qty, product_uom, company_id, values, po
):
"""Apply the discount to the created purchase order"""
res = super()._prepare_purchase_order_line(
product_id, product_qty, product_uom, values, po, partner
product_id, product_qty, product_uom, company_id, values, po
)
date = None
if po.date_order:
date = po.date_order.date()
seller = product_id._select_seller(
partner_id=partner, quantity=product_qty, date=date, uom_id=product_uom
partner_id=values["supplier"].name,
quantity=product_qty,
date=date,
uom_id=product_uom,
)
res.update(self._prepare_purchase_order_line_from_seller(seller))
return res
Expand Down
4 changes: 1 addition & 3 deletions purchase_discount/report/purchase_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

from odoo import fields, models

import odoo.addons.decimal_precision as dp


class PurchaseReport(models.Model):
_inherit = "purchase.report"

discount = fields.Float(
string="Discount (%)", digits=dp.get_precision("Discount"), group_operator="avg"
string="Discount (%)", digits="Discount", group_operator="avg"
)

def _select(self):
Expand Down
12 changes: 6 additions & 6 deletions purchase_discount/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Purchase order lines with discounts</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" 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" 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" href="https://github.com/OCA/purchase-workflow/tree/12.0/purchase_discount"><img alt="OCA/purchase-workflow" src="https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/purchase-workflow-12-0/purchase-workflow-12-0-purchase_discount"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/142/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" 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" 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" href="https://github.com/OCA/purchase-workflow/tree/13.0/purchase_discount"><img alt="OCA/purchase-workflow" src="https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/purchase-workflow-13-0/purchase-workflow-13-0-purchase_discount"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/142/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module allows to define a discount per line in the purchase orders. This
discount can be also negative, interpreting it as an increment.</p>
<p>It also modifies the purchase order report to include the discount field in it.</p>
Expand All @@ -378,16 +378,16 @@ <h1 class="title">Purchase order lines with discounts</h1>
discounted in price.</li>
<li>You can set prices and discounts on the same screen.</li>
</ul>
<img alt="https://raw.githubusercontent.com/OCA/purchase-workflow/12.0/purchase_discount/static/description/product_supplierinfo_form.png" src="https://raw.githubusercontent.com/OCA/purchase-workflow/12.0/purchase_discount/static/description/product_supplierinfo_form.png" />
<img alt="https://raw.githubusercontent.com/OCA/purchase-workflow/13.0/purchase_discount/static/description/product_supplierinfo_form.png" src="https://raw.githubusercontent.com/OCA/purchase-workflow/13.0/purchase_discount/static/description/product_supplierinfo_form.png" />
<ul class="simple">
<li>A new field default_supplierinfo_discount is added on res.partner model.
This value will be used as the default one, on each supplierinfo of that
supplier.</li>
</ul>
<img alt="https://raw.githubusercontent.com/OCA/purchase-workflow/12.0/purchase_discount/static/description/res_partner_company_form.png" src="https://raw.githubusercontent.com/OCA/purchase-workflow/12.0/purchase_discount/static/description/res_partner_company_form.png" />
<img alt="https://raw.githubusercontent.com/OCA/purchase-workflow/13.0/purchase_discount/static/description/res_partner_company_form.png" src="https://raw.githubusercontent.com/OCA/purchase-workflow/13.0/purchase_discount/static/description/res_partner_company_form.png" />
<p>Note: this setting is a new ‘company’ setting, unavailable for related
partners, as accounting-related Settings.</p>
<img alt="https://raw.githubusercontent.com/OCA/purchase-workflow/12.0/purchase_discount/static/description/res_partner_individual_form.png" src="https://raw.githubusercontent.com/OCA/purchase-workflow/12.0/purchase_discount/static/description/res_partner_individual_form.png" />
<img alt="https://raw.githubusercontent.com/OCA/purchase-workflow/13.0/purchase_discount/static/description/res_partner_individual_form.png" src="https://raw.githubusercontent.com/OCA/purchase-workflow/13.0/purchase_discount/static/description/res_partner_individual_form.png" />
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand Down Expand Up @@ -421,7 +421,7 @@ <h1><a class="toc-backref" href="#id3">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 smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_discount%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_discount%0Aversion:%2013.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">
Expand Down Expand Up @@ -462,7 +462,7 @@ <h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<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>This module is part of the <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/12.0/purchase_discount">OCA/purchase-workflow</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/13.0/purchase_discount">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>
Expand Down
29 changes: 10 additions & 19 deletions purchase_discount/tests/test_product_supplierinfo_discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,38 +79,29 @@ def test_004_prepare_purchase_order_line(self):
{
"sequence": 20,
"location_id": self.env.ref("stock.stock_location_locations").id,
"picking_type_id": self.env.ref("stock.chi_picking_type_in").id,
"picking_type_id": self.env.ref("stock.picking_type_in").id,
"warehouse_id": self.env.ref("stock.warehouse0").id,
"propagate": True,
"procure_method": "make_to_stock",
"route_sequence": 5.0,
"name": "YourCompany: Buy",
"route_id": self.env.ref("stock.route_warehouse0_mto").id,
"action": "buy",
}
)
po_line_vals = {
"origin": "SO012:WH: Stock -> Customers MTO",
"product_uom": self.env.ref("uom.product_uom_unit").id,
"product_qty": 50,
"location_id": self.env.ref("stock.stock_location_locations").id,
"company_id": self.env.ref("base.main_company"),
"state": "confirmed",
"warehouse_id": self.env.ref("stock.warehouse0").id,
"move_dest_id": self.env.ref("stock.stock_location_customers").id,
"message_unread_counter": 0,
"name": "WH: Stock -> Customers MTO",
"product_id": self.product.id,
"date_planned": fields.Datetime.now(),
"rule_id": stock_rule.id,
}
res = stock_rule._prepare_purchase_order_line(
self.product,
50,
self.env.ref("uom.product_uom_unit"),
po_line_vals,
self.env.ref("base.main_company"),
{
"supplier": self.supplierinfo,
"date_planned": fields.Datetime.now(),
"propagate_date": stock_rule.propagate_date,
"propagate_date_minimum_delta": stock_rule.propagate_date_minimum_delta,
"propagate_cancel": stock_rule.propagate_cancel,
"move_dest_id": [self.env.ref("stock.stock_location_customers").id],
},
self.purchase_order,
self.supplierinfo.name,
)
self.assertTrue(res.get("discount"), "Should have a discount key")

Expand Down
29 changes: 26 additions & 3 deletions purchase_discount/tests/test_purchase_discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ class TestPurchaseOrder(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestPurchaseOrder, cls).setUpClass()
cls.categ_cost_average = cls.env["product.category"].create(
{"name": "Average cost method category", "property_cost_method": "average"}
)
product_obj = cls.env["product.product"]
cls.product_1 = product_obj.create(
{"name": "Test product 1", "cost_method": "average"}
{"name": "Test product 1", "categ_id": cls.categ_cost_average.id}
)
cls.product_2 = product_obj.create({"name": "Test product 2"})
po_model = cls.env["purchase.order.line"]
Expand Down Expand Up @@ -40,12 +43,31 @@ def setUpClass(cls):
"price_unit": 10.0,
}
)
cls.account = cls.env["account.account"].create(
{
"name": "Test account",
"code": "TEST",
"user_type_id": cls.env.ref("account.data_account_type_expenses").id,
}
)
cls.tax = cls.env["account.tax"].create(
{
"name": "Sample tax 15%",
"amount_type": "percent",
"type_tax_use": "purchase",
"amount": 15.0,
"invoice_repartition_line_ids": [
(0, 0, {"factor_percent": 100, "repartition_type": "base"}),
(
0,
0,
{
"factor_percent": 100,
"repartition_type": "tax",
"account_id": cls.account.id,
},
),
],
}
)
cls.po_line_2 = po_model.create(
Expand Down Expand Up @@ -113,13 +135,14 @@ def test_report_price_unit(self):
self.assertEqual(rec.discount, 50)

def test_invoice(self):
invoice = self.env["account.invoice"].new(
invoice = self.env["account.move"].new(
{
"type": "out_invoice",
"partner_id": self.env.ref("base.res_partner_3").id,
"purchase_id": self.purchase_order.id,
}
)
invoice.purchase_order_change()
invoice._onchange_purchase_auto_complete()
line = invoice.invoice_line_ids.filtered(
lambda x: x.purchase_line_id == self.po_line_1
)
Expand Down

0 comments on commit 3192d33

Please sign in to comment.