-
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.
[MIG] deltatech_sale_pallet:Migration to 17.0
- Loading branch information
1 parent
fee967b
commit 9b4ade2
Showing
19 changed files
with
848 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 Pallet | ||
=========== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:d11234cb5b2158cdf8304fedbad6387c61b820c5f6d7818a5e4d53d010993506 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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_pallet | ||
:alt: dhongu/deltatech | ||
|
||
|badge1| |badge2| |badge3| | ||
|
||
Features: | ||
- | ||
|
||
**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_pallet%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_pallet>`_ 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,5 @@ | ||
# © 2008-2021 Deltatech | ||
# See README.rst file on addons root folder for license details | ||
|
||
from . import models | ||
from . import wizard |
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-2021 Deltatech | ||
# See README.rst file on addons root folder for license details | ||
|
||
{ | ||
"name": "Sale Pallet", | ||
"summary": "Sale pallet", | ||
"version": "17.0.1.0.6", | ||
"category": "Sales", | ||
"author": "Terrabit, Dorin Hongu", | ||
"website": "https://www.terrabit.ro", | ||
"depends": ["sale_margin", "account"], | ||
"license": "LGPL-3", | ||
"data": ["views/product_view.xml", "views/invoice_view.xml"], | ||
"images": ["static/description/main_screenshot.png"], | ||
"development_status": "Beta", | ||
"maintainers": ["dhongu"], | ||
} |
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,8 @@ | ||
# © 2017-2019 Deltatech | ||
# See README.rst file on addons root folder for license details | ||
|
||
from . import sale | ||
from . import product_template | ||
from . import product_category | ||
from . import invoice | ||
from . import sale_report |
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,36 @@ | ||
# © 2008-2021 Deltatech | ||
# Dorin Hongu <dhongu(@)gmail(.)com | ||
# See README.rst file on addons root folder for license details | ||
|
||
|
||
from odoo import models | ||
|
||
|
||
class AccountInvoice(models.Model): | ||
_inherit = "account.move" | ||
|
||
def show_pallets_status(self): | ||
pallet_category = self.env["product.category"].search([("pallet", "=", True)]) | ||
pallet_product = self.env["product.product"].search([("categ_id", "in", pallet_category.ids)]) | ||
|
||
done_states = self.env["sale.report"]._get_done_states() | ||
domain = [ | ||
("partner_id", "=", self.partner_id.id), | ||
("product_id", "in", pallet_product.ids), | ||
("state", "in", done_states), | ||
] | ||
|
||
action = self.env["ir.actions.actions"]._for_xml_id("sale.action_order_report_all") | ||
|
||
action["domain"] = domain | ||
action["view_mode"] = "pivot" | ||
action["views"] = [(False, "pivot")] | ||
action["context"] = { | ||
"pivot_measures": ["qty_delivered", "qty_invoiced", "price_unit"], | ||
"pivot_column_groupby": [], | ||
"pivot_row_groupby": ["product_id", "price_unit"], | ||
"active_id": self._context.get("active_id"), | ||
"active_model": "sale.report", | ||
} | ||
# action['target'] = 'new' | ||
return action | ||
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,12 @@ | ||
# © 2008-2021 Deltatech | ||
# Dorin Hongu <dhongu(@)gmail(.)com | ||
# See README.rst file on addons root folder for license details | ||
|
||
|
||
from odoo import fields, models | ||
|
||
|
||
class ProductCategory(models.Model): | ||
_inherit = "product.category" | ||
|
||
pallet = fields.Boolean() |
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,21 @@ | ||
# © 2008-2021 Deltatech | ||
# Dorin Hongu <dhongu(@)gmail(.)com | ||
# See README.rst file on addons root folder for license details | ||
|
||
|
||
from odoo import fields, models | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = "product.template" | ||
|
||
pallet_product_id = fields.Many2one("product.product") | ||
pallet_qty_min = fields.Float(digits="Product Unit of Measure") # cantitatea minima pe palet | ||
pallet_price = fields.Float("Pallet Price", default=1.0, digits="Product Price", compute="_compute_pallet_price") | ||
|
||
def _compute_pallet_price(self): | ||
main_pricelist = self.env.ref("product.list0", False) | ||
for template in self: | ||
template = template.with_context(quantity=template.pallet_qty_min, pricelist=main_pricelist.id) | ||
prices = template._compute_template_price_no_inverse() | ||
template.pallet_price = prices.get(template.id, 0.0) | ||
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,66 @@ | ||
# © 2008-2021 Deltatech | ||
# See README.rst file on addons root folder for license details | ||
|
||
|
||
from odoo import api, models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = "sale.order" | ||
|
||
@api.onchange("order_line") | ||
def onchange_order_line(self): | ||
pallets = self.recompute_pallet_lines(delete_if_under=True) | ||
if pallets: | ||
for line in self.order_line: | ||
pallet = pallets.pop(line.product_id.id, False) | ||
if pallet: | ||
# line.product_uom_qty = max(pallet["product_uom_qty"], line.product_uom_qty) | ||
line.product_uom_qty = pallet["product_uom_qty"] | ||
|
||
for product_id in pallets: | ||
if pallets and pallets[product_id]["product_uom_qty"]: | ||
order_line = self.order_line.new(pallets[product_id]) | ||
order_line._onchange_product_id_warning() | ||
# order_line.product_uom_change() | ||
|
||
def recompute_pallet_lines(self, delete_if_under=False): | ||
pallets = {} | ||
for line in self.order_line: | ||
if line.product_id.pallet_product_id and line.product_id.pallet_qty_min: | ||
# search for lines with same pallet | ||
prod_with_pallet_lines = self.order_line.filtered( | ||
lambda p: p.product_id.pallet_product_id == line.product_id.pallet_product_id | ||
) | ||
|
||
# compute sum for all lines with pallets | ||
qty = 0 | ||
for prod_with_pallet_line in prod_with_pallet_lines: | ||
qty += prod_with_pallet_line.compute_pallet_number(delete_if_under) | ||
|
||
pallets[line.product_id.pallet_product_id.id] = { | ||
"product_uom_qty": qty, | ||
"product_id": line.product_id.pallet_product_id.id, | ||
"state": "draft", | ||
"order_id": self.id, | ||
} | ||
return pallets | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = "sale.order.line" | ||
|
||
def compute_pallet_number(self, delete_if_under=False): | ||
self.ensure_one() | ||
if self.product_id.pallet_product_id and self.product_id.pallet_qty_min: | ||
if self.product_id.pallet_qty_min > self.product_uom_qty: | ||
if delete_if_under: | ||
return 0 | ||
else: | ||
return 1 | ||
else: | ||
pallets = self.product_uom_qty / self.product_id.pallet_qty_min | ||
if delete_if_under: | ||
return round(pallets - 0.49) # round down | ||
else: | ||
return round(pallets + 0.49) # round up | ||
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,69 @@ | ||
# © 2008-2021 Deltatech | ||
# Dorin Hongu <dhongu(@)gmail(.)com | ||
# See README.rst file on addons root folder for license details | ||
|
||
import re | ||
|
||
from odoo import api, fields, models | ||
from odoo.tools.safe_eval import safe_eval | ||
|
||
|
||
class SaleReport(models.Model): | ||
_inherit = "sale.report" | ||
|
||
price_unit = fields.Float(string="Price Unit", digits="Product Price", group_operator="avg") | ||
|
||
def _query(self, with_clause="", fields=None, groupby="", from_clause=""): | ||
if fields is None: | ||
fields = {} | ||
fields[ | ||
"price_unit" | ||
] = """, | ||
CASE WHEN l.product_id IS NOT NULL | ||
THEN sum(l.untaxed_amount_invoiced / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) / | ||
CASE COALESCE(sum(l.qty_invoiced / u.factor * u2.factor), 0) | ||
WHEN 0 | ||
THEN 1.0 | ||
ELSE sum(l.qty_invoiced / u.factor * u2.factor) | ||
END | ||
ELSE 0 | ||
END as price_unit | ||
""" | ||
sql = super()._query(with_clause, fields, groupby, from_clause) | ||
return sql | ||
|
||
@api.model | ||
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True): | ||
new_fields = [] | ||
new_fields += fields | ||
|
||
price_unit_field = next((field for field in fields if re.search(r"\bprice_unit\b", field)), False) | ||
amount_field = next((field for field in fields if re.search(r"\buntaxed_amount_invoiced\b", field)), False) | ||
qty_field = next((field for field in fields if re.search(r"\bqty_invoiced\b", field)), False) | ||
|
||
get_param = self.env["ir.config_parameter"].sudo().get_param | ||
price_coef = safe_eval(get_param("sale_pallet.price_coef", "1")) | ||
|
||
if price_unit_field: | ||
# new_fields.remove('payment_days') | ||
if not amount_field: | ||
new_fields.append("untaxed_amount_invoiced") | ||
if not qty_field: | ||
new_fields.append("qty_invoiced") | ||
|
||
res = super().read_group(domain, new_fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy) | ||
|
||
if price_unit_field: | ||
for line in res: | ||
amount = line.get("untaxed_amount_invoiced", 0.0) | ||
qty = line.get("qty_invoiced", 0.0) | ||
if amount and qty: | ||
line["price_unit"] = price_coef * amount / qty | ||
else: | ||
line["price_unit"] = 0.0 | ||
|
||
return res | ||
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: | ||
- |
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.