diff --git a/nfu_sale_order_packaging/__manifest__.py b/nfu_sale_order_packaging/__manifest__.py
index 81a61c0..9449913 100644
--- a/nfu_sale_order_packaging/__manifest__.py
+++ b/nfu_sale_order_packaging/__manifest__.py
@@ -3,7 +3,7 @@
"summary": "Add minimum and maximum order quantities to sale orders and use default packaging",
"author": "BAKEUP",
"website": "https://www.bakeup.org",
- "category": "Stock",
+ "category": "Sale",
"version": "16.0.0.0.1",
"depends": ["sale", "sale_order_batch"],
"data": [
diff --git a/nfu_sale_order_packaging/models/sale_order_line.py b/nfu_sale_order_packaging/models/sale_order_line.py
index a0bd60b..7f6bd31 100644
--- a/nfu_sale_order_packaging/models/sale_order_line.py
+++ b/nfu_sale_order_packaging/models/sale_order_line.py
@@ -10,6 +10,11 @@ class SaleOrderLine(models.Model):
@api.constrains("product_uom_qty", "product_uom_max_qty")
def _check_product_uom_qty(self):
- for record in self:
- if record.product_uom_max_qty != 0 and record.product_uom_qty > record.product_uom_max_qty:
- raise UserError(_("The quantity must be less than or equal to the maximum quantity."))
+ for order_line in self:
+ if order_line.product_uom_max_qty != 0 and order_line.product_uom_qty > order_line.product_uom_max_qty:
+ raise UserError(
+ _(
+ f"{order_line.order_id.name},{order_line.product_id.name}:"
+ "The quantity must be less than or equal to the maximum quantity."
+ )
+ )
diff --git a/nfu_sale_order_packaging/views/sale_order_batch_product_views.xml b/nfu_sale_order_packaging/views/sale_order_batch_product_views.xml
index 0906e95..acac722 100644
--- a/nfu_sale_order_packaging/views/sale_order_batch_product_views.xml
+++ b/nfu_sale_order_packaging/views/sale_order_batch_product_views.xml
@@ -10,9 +10,14 @@
+
+
diff --git a/nfu_sale_order_packaging/views/sale_order_batch_views.xml b/nfu_sale_order_packaging/views/sale_order_batch_views.xml
index aa7516b..ec519f8 100644
--- a/nfu_sale_order_packaging/views/sale_order_batch_views.xml
+++ b/nfu_sale_order_packaging/views/sale_order_batch_views.xml
@@ -7,9 +7,14 @@
+
+
diff --git a/nfu_sale_order_packaging/views/sale_order_views.xml b/nfu_sale_order_packaging/views/sale_order_views.xml
index f0d2742..4922441 100644
--- a/nfu_sale_order_packaging/views/sale_order_views.xml
+++ b/nfu_sale_order_packaging/views/sale_order_views.xml
@@ -5,8 +5,10 @@
sale.order
-
+
+
+
diff --git a/sale_order_batch/models/sale_order_batch.py b/sale_order_batch/models/sale_order_batch.py
index 59afb0a..1bea44b 100644
--- a/sale_order_batch/models/sale_order_batch.py
+++ b/sale_order_batch/models/sale_order_batch.py
@@ -47,6 +47,8 @@ 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.Many2many("sale.order.line", compute="_compute_sale_order_line_ids", store=True)
+ invoice_ids = fields.Many2many("account.move", compute="_compute_invoice_ids")
+ invoice_count = fields.Integer(compute="_compute_invoice_ids")
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")
@@ -60,17 +62,24 @@ class SaleOrderBatch(models.Model):
else:
batch.validity_date = False
- @api.depends("sale_order_ids")
- def _compute_sale_order_count(self):
- for batch in self:
- batch.sale_order_count = len(batch.sale_order_ids)
-
@api.depends("sale_order_ids.order_line")
def _compute_sale_order_line_ids(self):
for batch in self:
order_lines = self.env["sale.order.line"].search([("order_id", "in", batch.sale_order_ids.ids)])
batch.sale_order_line_ids = order_lines
+ @api.depends("sale_order_ids")
+ def _compute_sale_order_count(self):
+ for batch in self:
+ batch.sale_order_count = len(batch.sale_order_ids)
+
+ @api.depends("sale_order_ids.invoice_ids")
+ def _compute_invoice_ids(self):
+ for batch in self:
+ invoices = batch.sale_order_ids.mapped("invoice_ids")
+ batch.invoice_ids = invoices
+ batch.invoice_count = len(invoices)
+
@api.depends("sale_order_ids.amount_total")
def _compute_amount_total(self):
for batch in self:
@@ -113,6 +122,25 @@ class SaleOrderBatch(models.Model):
result = {"type": "ir.actions.act_window_close"}
return result
+ 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")
+ 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"]
+ else:
+ action["views"] = form_view
+ action["res_id"] = invoices.id
+ else:
+ action = {"type": "ir.actions.act_window_close"}
+
+ context = {"default_move_type": "out_invoice"}
+ action["context"] = context
+ return action
+
def action_confirm(self):
for batch in self:
orders = batch.with_context(bypass_batch=True).sale_order_ids
diff --git a/sale_order_batch/views/sale_order_batch_product_views.xml b/sale_order_batch/views/sale_order_batch_product_views.xml
index a1661e6..b6e6a46 100644
--- a/sale_order_batch/views/sale_order_batch_product_views.xml
+++ b/sale_order_batch/views/sale_order_batch_product_views.xml
@@ -26,6 +26,7 @@
+
diff --git a/sale_order_batch/views/sale_order_batch_views.xml b/sale_order_batch/views/sale_order_batch_views.xml
index 9370be8..88147e8 100644
--- a/sale_order_batch/views/sale_order_batch_views.xml
+++ b/sale_order_batch/views/sale_order_batch_views.xml
@@ -29,6 +29,19 @@
type="object"
attrs="{'invisible': [('state', '!=','open')]}"
/>
+
+
+
@@ -76,7 +98,6 @@
@@ -84,6 +105,14 @@
+
@@ -95,8 +124,9 @@
>
+
-
+