Skip to content

Commit

Permalink
[MIG] deltatech_sale_pallet:Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
VoicuStefan2001 committed Jan 5, 2024
1 parent fee967b commit 9b4ade2
Show file tree
Hide file tree
Showing 19 changed files with 848 additions and 0 deletions.
65 changes: 65 additions & 0 deletions deltatech_sale_pallet/README.rst
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.
5 changes: 5 additions & 0 deletions deltatech_sale_pallet/__init__.py
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
17 changes: 17 additions & 0 deletions deltatech_sale_pallet/__manifest__.py
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"],
}
8 changes: 8 additions & 0 deletions deltatech_sale_pallet/models/__init__.py
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
36 changes: 36 additions & 0 deletions deltatech_sale_pallet/models/invoice.py
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)])

Check warning on line 14 in deltatech_sale_pallet/models/invoice.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/invoice.py#L13-L14

Added lines #L13 - L14 were not covered by tests

done_states = self.env["sale.report"]._get_done_states()
domain = [

Check warning on line 17 in deltatech_sale_pallet/models/invoice.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/invoice.py#L16-L17

Added lines #L16 - L17 were not covered by tests
("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")

Check warning on line 23 in deltatech_sale_pallet/models/invoice.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/invoice.py#L23

Added line #L23 was not covered by tests

action["domain"] = domain
action["view_mode"] = "pivot"
action["views"] = [(False, "pivot")]
action["context"] = {

Check warning on line 28 in deltatech_sale_pallet/models/invoice.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/invoice.py#L25-L28

Added lines #L25 - L28 were not covered by tests
"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

Check warning on line 36 in deltatech_sale_pallet/models/invoice.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/invoice.py#L36

Added line #L36 was not covered by tests
12 changes: 12 additions & 0 deletions deltatech_sale_pallet/models/product_category.py
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()
21 changes: 21 additions & 0 deletions deltatech_sale_pallet/models/product_template.py
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)

Check warning on line 17 in deltatech_sale_pallet/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/product_template.py#L17

Added line #L17 was not covered by tests
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)

Check warning on line 21 in deltatech_sale_pallet/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/product_template.py#L19-L21

Added lines #L19 - L21 were not covered by tests
66 changes: 66 additions & 0 deletions deltatech_sale_pallet/models/sale.py
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"]

Check warning on line 19 in deltatech_sale_pallet/models/sale.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/sale.py#L19

Added line #L19 was not covered by tests

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

Check warning on line 58 in deltatech_sale_pallet/models/sale.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/sale.py#L58

Added line #L58 was not covered by tests
else:
return 1

Check warning on line 60 in deltatech_sale_pallet/models/sale.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/sale.py#L60

Added line #L60 was not covered by tests
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

Check warning on line 66 in deltatech_sale_pallet/models/sale.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/sale.py#L66

Added line #L66 was not covered by tests
69 changes: 69 additions & 0 deletions deltatech_sale_pallet/models/sale_report.py
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[

Check warning on line 19 in deltatech_sale_pallet/models/sale_report.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/sale_report.py#L18-L19

Added lines #L18 - L19 were not covered by tests
"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

Check warning on line 37 in deltatech_sale_pallet/models/sale_report.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/sale_report.py#L36-L37

Added lines #L36 - L37 were not covered by tests

@api.model
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
new_fields = []
new_fields += fields

Check warning on line 42 in deltatech_sale_pallet/models/sale_report.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/sale_report.py#L41-L42

Added lines #L41 - L42 were not covered by tests

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"))

Check warning on line 49 in deltatech_sale_pallet/models/sale_report.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/sale_report.py#L48-L49

Added lines #L48 - L49 were not covered by tests

if price_unit_field:
# new_fields.remove('payment_days')
if not amount_field:
new_fields.append("untaxed_amount_invoiced")

Check warning on line 54 in deltatech_sale_pallet/models/sale_report.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/sale_report.py#L54

Added line #L54 was not covered by tests
if not qty_field:
new_fields.append("qty_invoiced")

Check warning on line 56 in deltatech_sale_pallet/models/sale_report.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/sale_report.py#L56

Added line #L56 was not covered by tests

res = super().read_group(domain, new_fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy)

Check warning on line 58 in deltatech_sale_pallet/models/sale_report.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/sale_report.py#L58

Added line #L58 was not covered by tests

if price_unit_field:
for line in res:
amount = line.get("untaxed_amount_invoiced", 0.0)
qty = line.get("qty_invoiced", 0.0)

Check warning on line 63 in deltatech_sale_pallet/models/sale_report.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/sale_report.py#L62-L63

Added lines #L62 - L63 were not covered by tests
if amount and qty:
line["price_unit"] = price_coef * amount / qty

Check warning on line 65 in deltatech_sale_pallet/models/sale_report.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/sale_report.py#L65

Added line #L65 was not covered by tests
else:
line["price_unit"] = 0.0

Check warning on line 67 in deltatech_sale_pallet/models/sale_report.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/sale_report.py#L67

Added line #L67 was not covered by tests

return res

Check warning on line 69 in deltatech_sale_pallet/models/sale_report.py

View check run for this annotation

Codecov / codecov/patch

deltatech_sale_pallet/models/sale_report.py#L69

Added line #L69 was not covered by tests
2 changes: 2 additions & 0 deletions deltatech_sale_pallet/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Features:
-
Binary file added deltatech_sale_pallet/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9b4ade2

Please sign in to comment.