-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1170 from VoicuStefan2001/17.0-mig-deltatech_sale…
…_multiple [17.0][MIG] deltatech_sale_multiple:Migration to 17.0
- Loading branch information
Showing
13 changed files
with
736 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
================= | ||
Sale Qty Multiple | ||
================= | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:b580a2403b01fe7ec1849bdf0e8b0fa279743eb57d097aa0f89f8c0cba2605b3 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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-dhongu%2Fdeltatech-lightgray.png?logo=github | ||
:target: https://github.com/dhongu/deltatech/tree/17.0/deltatech_sale_multiple | ||
:alt: dhongu/deltatech | ||
|
||
|badge1| |badge2| |badge3| | ||
|
||
Features: | ||
- Sale of multiple quantity | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/dhongu/deltatech/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/dhongu/deltatech/issues/new?body=module:%20deltatech_sale_multiple%0Aversion:%2017.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 | ||
~~~~~~~ | ||
|
||
* Terrabit | ||
* Dorin Hongu | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
.. |maintainer-dhongu| image:: https://github.com/dhongu.png?size=40px | ||
:target: https://github.com/dhongu | ||
:alt: dhongu | ||
|
||
Current maintainer: | ||
|
||
|maintainer-dhongu| | ||
|
||
This module is part of the `dhongu/deltatech <https://github.com/dhongu/deltatech/tree/17.0/deltatech_sale_multiple>`_ project on GitHub. | ||
|
||
You are welcome to contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# © 2008-2019 Deltatech | ||
# Dorin Hongu <dhongu(@)gmail(.)com | ||
# See README.rst file on addons root folder for license details | ||
|
||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# © 2008-2019 Deltatech | ||
# Dorin Hongu <dhongu(@)gmail(.)com | ||
# See README.rst file on addons root folder for license details | ||
{ | ||
"name": "Sale Qty Multiple", | ||
"summary": "Sale quantity multiple", | ||
"version": "17.0.1.0.0", | ||
"author": "Terrabit, Dorin Hongu", | ||
"website": "https://www.terrabit.ro", | ||
"category": "Sales", | ||
"depends": ["sale_stock"], | ||
"license": "LGPL-3", | ||
"data": ["views/product_view.xml"], | ||
"images": ["images/main_screenshot.png"], | ||
"development_status": "Beta", | ||
"maintainers": ["dhongu"], | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# © 2008-2019 Deltatech | ||
# Dorin Hongu <dhongu(@)gmail(.)com | ||
# See README.rst file on addons root folder for license details | ||
|
||
from . import product | ||
from . import sale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# © 2008-2021 Deltatech | ||
# Dorin Hongu <dhongu(@)gmail(.)com | ||
# See README.rst file on addons root folder for license details | ||
|
||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = "product.template" | ||
|
||
qty_multiple = fields.Float( | ||
"Qty Multiple", | ||
digits="Product Unit of Measure", | ||
default=1, | ||
compute="_compute_qty_multiple", | ||
inverse="_inverse_qty_multiple", | ||
store=True, | ||
help="The sale quantity will be rounded up to this multiple. If it is 0, the exact quantity will be used.", | ||
) | ||
qty_minim = fields.Float( | ||
"Qty Minim", | ||
digits="Product Unit of Measure", | ||
default=1, | ||
compute="_compute_qty_multiple", | ||
inverse="_inverse_qty_minim", | ||
store=True, | ||
help="The minim sale quantity will. If it is 0, the exact quantity will be used.", | ||
) | ||
|
||
@api.depends("product_variant_ids", "product_variant_ids.qty_multiple") | ||
def _compute_qty_multiple(self): | ||
unique_variants = self.filtered(lambda template: len(template.product_variant_ids) == 1) | ||
for template in unique_variants: | ||
template.qty_multiple = template.product_variant_ids.qty_multiple | ||
template.qty_minim = template.product_variant_ids.qty_minim | ||
for template in self - unique_variants: | ||
template.qty_multiple = "-1" | ||
template.qty_minim = "-1" | ||
|
||
def _inverse_qty_multiple(self): | ||
for product in self: | ||
if len(product.product_variant_ids) == 1: | ||
product.product_variant_ids.qty_multiple = product.qty_multiple | ||
|
||
def _inverse_qty_minim(self): | ||
for product in self: | ||
if len(product.product_variant_ids) == 1: | ||
product.product_variant_ids.qty_minim = product.qty_minim | ||
|
||
|
||
class ProductProduct(models.Model): | ||
_inherit = "product.product" | ||
|
||
qty_multiple = fields.Float( | ||
"Qty Multiple", | ||
digits="Product Unit of Measure", | ||
default=1, | ||
help="The sale quantity will be rounded up to this multiple. If it is 0, the exact quantity will be used.", | ||
) | ||
qty_minim = fields.Float("Qty Minim", digits="Product Unit of Measure", default=1, help="The minim sale quantity. ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# © 2008-2021 Deltatech | ||
# Dorin Hongu <dhongu(@)gmail(.)com | ||
# See README.rst file on addons root folder for license details | ||
|
||
|
||
from odoo import api, models | ||
from odoo.tools import float_compare, float_round | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = "sale.order.line" | ||
|
||
@api.model | ||
def fix_qty_multiple(self, product, product_uom, qty=None): | ||
if qty is None: | ||
qty = 0 | ||
|
||
if product.qty_multiple and product.qty_multiple != 1: | ||
qty_multiple = product.qty_multiple | ||
remainder = qty % qty_multiple | ||
|
||
if float_compare(remainder, 0.0, precision_rounding=product_uom.rounding) > 0: | ||
qty += qty_multiple - remainder | ||
|
||
if float_compare(qty, 0.0, precision_rounding=product_uom.rounding) > 0: | ||
qty = float_round(qty, precision_rounding=product_uom.rounding) | ||
if product.qty_minim and product.qty_minim > 0: | ||
if qty < product.qty_minim: | ||
qty = product.qty_minim | ||
|
||
return qty | ||
|
||
@api.onchange("product_uom_qty", "product_id") | ||
def _onchange_product_uom_qty(self): | ||
product_uom = self.product_uom or self.product_id.uom_id | ||
self.product_uom_qty = self.fix_qty_multiple(self.product_id, product_uom, self.product_uom_qty) | ||
# super(SaleOrderLine, self)._onchange_product_uom_qty() | ||
|
||
def write(self, vals): | ||
if len(self) == 1 and "product_uom_qty" in vals: | ||
if "product_id" in vals: | ||
product = self.env["product.product"].browse(vals["product_id"]) | ||
else: | ||
product = self.product_id | ||
if "product_uom" in vals: | ||
product_uom = self.env["uom.uom"].browse(vals["product_uom"]) | ||
else: | ||
product_uom = self.product_uom | ||
vals["product_uom_qty"] = self.fix_qty_multiple(product, product_uom, vals["product_uom_qty"]) | ||
|
||
super().write(vals) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Features: | ||
- Sale of multiple quantity |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.