From c1e229ef72a1c1c8fbe2dab58d3bcbe09af40329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20G=C3=B6ttsch?= Date: Thu, 24 Jul 2025 08:06:28 +0200 Subject: [PATCH] [chore] update pre-commits --- sale_order_batch/README.rst | 12 ++--- sale_order_batch/models/sale_order.py | 11 +++- sale_order_batch/models/sale_order_batch.py | 54 ++++++++++++++----- .../models/sale_order_batch_product.py | 52 +++++++++++++----- sale_order_batch/models/sale_order_line.py | 9 +++- .../static/description/index.html | 8 +-- 6 files changed, 108 insertions(+), 38 deletions(-) diff --git a/sale_order_batch/README.rst b/sale_order_batch/README.rst index 618b60d..f52642d 100644 --- a/sale_order_batch/README.rst +++ b/sale_order_batch/README.rst @@ -16,9 +16,9 @@ Sale Order Batch .. |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-bruecksen%2Fife_nfu-lightgray.png?logo=github - :target: https://github.com/bruecksen/ife_nfu/tree/16.0/sale_order_batch - :alt: bruecksen/ife_nfu +.. |badge3| image:: https://img.shields.io/badge/github-bruecksen%2Fnfu-lightgray.png?logo=github + :target: https://github.com/bruecksen/nfu/tree/16.0/sale_order_batch + :alt: bruecksen/nfu |badge1| |badge2| |badge3| @@ -48,10 +48,10 @@ Changelog Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. +Bugs are tracked on `GitHub 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -71,6 +71,6 @@ Contributors Maintainers ~~~~~~~~~~~ -This module is part of the `bruecksen/ife_nfu `_ project on GitHub. +This module is part of the `bruecksen/nfu `_ project on GitHub. You are welcome to contribute. diff --git a/sale_order_batch/models/sale_order.py b/sale_order_batch/models/sale_order.py index 46c2f56..5398cc1 100644 --- a/sale_order_batch/models/sale_order.py +++ b/sale_order_batch/models/sale_order.py @@ -5,7 +5,12 @@ from odoo.exceptions import UserError class SaleOrder(models.Model): _inherit = "sale.order" - batch_id = fields.Many2one("sale.order.batch", copy=False, check_company=True, domain="[('state','!=','closed')]") + batch_id = fields.Many2one( + "sale.order.batch", + copy=False, + check_company=True, + domain="[('state','!=','closed')]", + ) def _get_current_batch(self): """ @@ -47,7 +52,9 @@ class SaleOrder(models.Model): if order.batch_id: invalid_orders.append(order.name) if invalid_orders: - raise UserError(_(f"Sale Order belongs to a Batch: {', '.join(invalid_orders)}")) + raise UserError( + _(f"Sale Order belongs to a Batch: {', '.join(invalid_orders)}") + ) return super().action_confirm() def write(self, vals): diff --git a/sale_order_batch/models/sale_order_batch.py b/sale_order_batch/models/sale_order_batch.py index c40b53f..eac06e2 100644 --- a/sale_order_batch/models/sale_order_batch.py +++ b/sale_order_batch/models/sale_order_batch.py @@ -3,7 +3,12 @@ from odoo import _, api, fields, models from odoo.addons.sale.models.sale_order import INVOICE_STATUS -STATES = [("open", "Open"), ("in_progress", "In Progress"), ("closed", "Closed"), ("cancel", "Cancelled")] +STATES = [ + ("open", "Open"), + ("in_progress", "In Progress"), + ("closed", "Closed"), + ("cancel", "Cancelled"), +] READONLY_FIELD_STATES = {state: [("readonly", True)] for state in {"closed"}} @@ -25,10 +30,19 @@ class SaleOrderBatch(models.Model): default=lambda self: _("New"), ) company_id = fields.Many2one( - comodel_name="res.company", required=True, index=True, default=lambda self: self.env.company + comodel_name="res.company", + required=True, + index=True, + default=lambda self: self.env.company, ) state = fields.Selection( - selection=STATES, string="Status", readonly=True, copy=False, index=True, tracking=1, default="open" + selection=STATES, + string="Status", + readonly=True, + copy=False, + index=True, + tracking=1, + default="open", ) date_order = fields.Datetime( string="Order Date", @@ -41,10 +55,14 @@ class SaleOrderBatch(models.Model): ) sale_order_ids = fields.One2many("sale.order", "batch_id") sale_order_count = fields.Integer(compute="_compute_sale_order_count") - sale_order_line_ids = fields.One2many("sale.order.line", "batch_id", states=READONLY_FIELD_STATES) + sale_order_line_ids = fields.One2many( + "sale.order.line", "batch_id", states=READONLY_FIELD_STATES + ) invoice_ids = fields.Many2many("account.move", compute="_compute_invoice_ids") invoice_count = fields.Integer(compute="_compute_invoice_ids") - invoice_status = fields.Selection(selection=INVOICE_STATUS, compute="_compute_invoice_status", store=True) + invoice_status = fields.Selection( + selection=INVOICE_STATUS, compute="_compute_invoice_status", store=True + ) amount_total = fields.Float(compute="_compute_amount_total", string="Total") product_ids = fields.One2many("sale.order.batch.product", "batch_id") product_count = fields.Integer(compute="_compute_product_count") @@ -66,11 +84,13 @@ class SaleOrderBatch(models.Model): def _compute_invoice_status(self): for batch in self: if batch.sale_order_ids and any( - invoice_status == "to invoice" for invoice_status in batch.sale_order_ids.mapped("invoice_status") + invoice_status == "to invoice" + for invoice_status in batch.sale_order_ids.mapped("invoice_status") ): batch.invoice_status = "to invoice" elif batch.sale_order_ids and all( - invoice_status == "invoiced" for invoice_status in batch.sale_order_ids.mapped("invoice_status") + invoice_status == "invoiced" + for invoice_status in batch.sale_order_ids.mapped("invoice_status") ): batch.invoice_status = "invoiced" elif batch.sale_order_ids and all( @@ -113,11 +133,15 @@ class SaleOrderBatch(models.Model): def action_view_products(self): self.ensure_one() - result = self.env["ir.actions.act_window"]._for_xml_id("product.product_normal_action_sell") + result = self.env["ir.actions.act_window"]._for_xml_id( + "product.product_normal_action_sell" + ) if len(self.product_ids) > 1: result["domain"] = [("id", "in", self.product_ids.ids)] elif len(self.product_ids) == 1: - result["views"] = [(self.env.ref("product.product_product_tree_view", False).id, "form")] + result["views"] = [ + (self.env.ref("product.product_product_tree_view", False).id, "form") + ] result["res_id"] = self.product_ids.id else: result = {"type": "ir.actions.act_window_close"} @@ -125,13 +149,17 @@ class SaleOrderBatch(models.Model): def action_view_invoice(self): invoices = self.mapped("invoice_ids") - action = self.env["ir.actions.actions"]._for_xml_id("account.action_move_out_invoice_type") + action = self.env["ir.actions.actions"]._for_xml_id( + "account.action_move_out_invoice_type" + ) if len(invoices) > 1: action["domain"] = [("id", "in", invoices.ids)] elif len(invoices) == 1: form_view = [(self.env.ref("account.view_move_form").id, "form")] if "views" in action: - action["views"] = form_view + [(state, view) for state, view in action["views"] if view != "form"] + action["views"] = form_view + [ + (state, view) for state, view in action["views"] if view != "form" + ] else: action["views"] = form_view action["res_id"] = invoices.id @@ -169,5 +197,7 @@ class SaleOrderBatch(models.Model): if "company_id" in vals: self = self.with_company(vals["company_id"]) if vals.get("name", _("New")) == _("New"): - vals["name"] = self.env["ir.sequence"].next_by_code("sale.order.batch") or _("New") + vals["name"] = self.env["ir.sequence"].next_by_code( + "sale.order.batch" + ) or _("New") return super().create(vals_list) diff --git a/sale_order_batch/models/sale_order_batch_product.py b/sale_order_batch/models/sale_order_batch_product.py index f22c443..5a78e45 100644 --- a/sale_order_batch/models/sale_order_batch_product.py +++ b/sale_order_batch/models/sale_order_batch_product.py @@ -19,14 +19,26 @@ class SaleOrderBatchProduct(models.Model): readonly=True, ) state = fields.Selection(related="batch_id.state") - product_id = fields.Many2one(comodel_name="product.product", required=True, readonly=True) - product_template_id = fields.Many2one( - "product.template", related="product_id.product_tmpl_id", string="Product Template" + product_id = fields.Many2one( + comodel_name="product.product", required=True, readonly=True + ) + product_template_id = fields.Many2one( + "product.template", + related="product_id.product_tmpl_id", + string="Product Template", + ) + sale_order_line_ids = fields.One2many( + "sale.order.line", "batch_product_id", states=READONLY_FIELD_STATES + ) + product_uom_category_id = fields.Many2one( + related="product_id.uom_id.category_id", depends=["product_id"] ) - sale_order_line_ids = fields.One2many("sale.order.line", "batch_product_id", states=READONLY_FIELD_STATES) - product_uom_category_id = fields.Many2one(related="product_id.uom_id.category_id", depends=["product_id"]) product_uom_qty = fields.Float( - string="Quantity", compute="_compute_uom_qty", precompute=True, store=True, digits=[12, 3] + string="Quantity", + compute="_compute_uom_qty", + precompute=True, + store=True, + digits=[12, 3], ) product_uom = fields.Many2one(related="product_id.uom_id") lst_price = fields.Float( @@ -50,26 +62,42 @@ class SaleOrderBatchProduct(models.Model): @api.constrains("product_id", "sale_order_line_ids") def _check_sale_order_line_products(self): for product in self: - if any(line.product_id != product.product_id for line in product.sale_order_line_ids): + if any( + line.product_id != product.product_id + for line in product.sale_order_line_ids + ): raise ValueError("Product must be the same for all Sale Order Lines") @api.depends("sale_order_line_ids.product_uom_qty") def _compute_uom_qty(self): for product in self: - product.product_uom_qty = sum(product.sale_order_line_ids.mapped("product_uom_qty")) + product.product_uom_qty = sum( + product.sale_order_line_ids.mapped("product_uom_qty") + ) @api.depends("product_id", "product_uom_qty", "product_uom") def _compute_product_packaging_id(self): for line in self: # remove packaging if not match the product - if line.product_packaging_id and line.product_packaging_id.product_id != line.product_id: + if ( + line.product_packaging_id + and line.product_packaging_id.product_id != line.product_id + ): line.product_packaging_id = False # suggest always the first packaging if line.product_id and line.product_uom_qty and line.product_uom: - suggested_packaging = line.product_id.packaging_ids[0] if line.product_id.packaging_ids else False - line.product_packaging_id = suggested_packaging or line.product_packaging_id + suggested_packaging = ( + line.product_id.packaging_ids[0] + if line.product_id.packaging_ids + else False + ) + line.product_packaging_id = ( + suggested_packaging or line.product_packaging_id + ) @api.depends("product_packaging_id") def _compute_product_packaging_qty(self): for product in self: - product.product_packaging_qty = product.product_packaging_id.qty if product.product_packaging_id else 1 + product.product_packaging_qty = ( + product.product_packaging_id.qty if product.product_packaging_id else 1 + ) diff --git a/sale_order_batch/models/sale_order_line.py b/sale_order_batch/models/sale_order_line.py index 652fc66..0af31ae 100644 --- a/sale_order_batch/models/sale_order_line.py +++ b/sale_order_batch/models/sale_order_line.py @@ -12,7 +12,11 @@ class SaleOrderLine(models.Model): for line in lines_with_batch: batch_id = line.batch_id batch_product = self.env["sale.order.batch.product"].search( - [("product_id", "=", line.product_id.id), ("batch_id", "=", batch_id.id)], limit=1 + [ + ("product_id", "=", line.product_id.id), + ("batch_id", "=", batch_id.id), + ], + limit=1, ) if not batch_product: batch_product = self.env["sale.order.batch.product"].create( @@ -30,7 +34,8 @@ class SaleOrderLine(models.Model): lines_with_batch = self.filtered(lambda l: l.batch_id) lines_without_batch = self - lines_with_batch lines_with_batch.filtered( - lambda l: l.batch_product_id and l.batch_product_id.product_id != l.product_id + lambda l: l.batch_product_id + and l.batch_product_id.product_id != l.product_id )._unlink_batch_product() lines_with_batch._link_batch_product() lines_without_batch._unlink_batch_product() diff --git a/sale_order_batch/static/description/index.html b/sale_order_batch/static/description/index.html index 26b6e56..331fa37 100644 --- a/sale_order_batch/static/description/index.html +++ b/sale_order_batch/static/description/index.html @@ -369,7 +369,7 @@ ul.auto-toc { !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:6686f0672ede8093b17d5d7b165f72f8e49341c7849f9e0d5a162e350fc36d71 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: LGPL-3 bruecksen/ife_nfu

+

Beta License: LGPL-3 bruecksen/nfu

This module adds the possibility to group Sale orders into batches. Attributes of a Sale Order Batch will be written to all Sale Order. Wenn attached to a batch they can be processed together. On the other hand they cannot be proccesed individual anymore as log as they are part of a batch. Only Sale Orders in state Qutotation or Quotation Send can be attached to a batch.

@@ -417,10 +417,10 @@ anymore as log as they are part of a batch. Only Sale Orders in state Qutotation

Bug Tracker

-

Bugs are tracked on GitHub Issues. +

Bugs are tracked on GitHub 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.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -439,7 +439,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

Maintainers

-

This module is part of the bruecksen/ife_nfu project on GitHub.

+

This module is part of the bruecksen/nfu project on GitHub.

You are welcome to contribute.