diff --git a/nfu_sale_product_min_max_qty/__manifest__.py b/nfu_sale_product_min_max_qty/__manifest__.py
index 0733755..01a3732 100644
--- a/nfu_sale_product_min_max_qty/__manifest__.py
+++ b/nfu_sale_product_min_max_qty/__manifest__.py
@@ -9,6 +9,7 @@
"data": [
"views/sale_order_views.xml",
"views/sale_order_line_views.xml",
+ "wizard/sale_max_qty_line_views.xml",
"wizard/sale_max_qty_chooser_views.xml",
"views/templates.xml",
"security/ir.model.access.csv",
diff --git a/nfu_sale_product_min_max_qty/models/sale_order.py b/nfu_sale_product_min_max_qty/models/sale_order.py
index 2b388c5..5b0fe98 100644
--- a/nfu_sale_product_min_max_qty/models/sale_order.py
+++ b/nfu_sale_product_min_max_qty/models/sale_order.py
@@ -24,13 +24,15 @@ class SaleOrder(models.Model):
action = {
"name": _("Min max qty wizard"),
"type": "ir.actions.act_window",
- "res_model": "sale.max.qty.chooser",
- "view_mode": "form",
- "target": "new",
- "res_id": sale_max_qty_chooser.id,
+ "res_model": "sale.max.qty.line",
+ "view_mode": "tree",
+ "target": "current",
+ "editable": True,
+ "context": {"search_default_group_by_product": 1},
+ "domain": [("id", "in", sale_max_qty_chooser.sale_max_qty_ids.ids)],
}
return action
-
+
def action_sale_order_lines(self):
"""
Here you need to create the wizzard objects first and then call the wizzard with the newly created id
@@ -40,6 +42,8 @@ class SaleOrder(models.Model):
"type": "ir.actions.act_window",
"res_model": "sale.order.line",
"view_mode": "tree,form",
+ "target": "current",
+ "context": {"group_by": "product_id"},
"domain": [("id", "in", self.order_line.ids)],
}
diff --git a/nfu_sale_product_min_max_qty/views/sale_order_line_views.xml b/nfu_sale_product_min_max_qty/views/sale_order_line_views.xml
index 6429131..0c93010 100644
--- a/nfu_sale_product_min_max_qty/views/sale_order_line_views.xml
+++ b/nfu_sale_product_min_max_qty/views/sale_order_line_views.xml
@@ -4,7 +4,7 @@
sale.order.line.tree
sale.order.line
-
+
diff --git a/nfu_sale_product_min_max_qty/wizard/sale_max_qty_chooser_views.xml b/nfu_sale_product_min_max_qty/wizard/sale_max_qty_chooser_views.xml
index ad902a5..0d4cd9e 100644
--- a/nfu_sale_product_min_max_qty/wizard/sale_max_qty_chooser_views.xml
+++ b/nfu_sale_product_min_max_qty/wizard/sale_max_qty_chooser_views.xml
@@ -1,24 +1,23 @@
-
Sale Max Quantity Chhooser
sale.max.qty.chooser
diff --git a/nfu_sale_product_min_max_qty/wizard/sale_max_qty_line.py b/nfu_sale_product_min_max_qty/wizard/sale_max_qty_line.py
index 4f2d9fc..ab4ff6b 100644
--- a/nfu_sale_product_min_max_qty/wizard/sale_max_qty_line.py
+++ b/nfu_sale_product_min_max_qty/wizard/sale_max_qty_line.py
@@ -1,4 +1,5 @@
-from odoo import fields, models, api
+from odoo import _, api, fields, models
+from odoo.exceptions import UserError
class SaleMaxQtyLine(models.TransientModel):
@@ -9,23 +10,37 @@ class SaleMaxQtyLine(models.TransientModel):
_name = "sale.max.qty.line"
_description = "Max qty Sale Order Lines"
+ name = fields.Char()
sale_max_qty_chooser = fields.Many2one("sale.max.qty.chooser")
qty = fields.Float()
max_qty = fields.Float(related="sale_line_id.product_uom_max_qty")
packaging_size = fields.Float(compute="_compute_packaging_size")
- quantity_fits_packaging = fields.Boolean(compute='_compute_quantity_fits_packaging')
+ quantity_fits_packaging = fields.Boolean(compute="_compute_quantity_fits_packaging")
+ total_quantity = fields.Float(compute="_compute_quantity_fits_packaging")
sale_line_id = fields.Many2one("sale.order.line")
- product_id = fields.Many2one(related="sale_line_id.product_id")
+ product_id = fields.Many2one(related="sale_line_id.product_id", store=True)
reset_to_draft = fields.Boolean()
def _compute_packaging_size(self):
- for sale_order in self:
- sale_order.packaging_size = min(sale_order.sale_line_id.product_id.packaging_ids.mapped('qty'), default=1.0)
+ for max_qty_line in self:
+ max_qty_line.packaging_size = min(
+ max_qty_line.sale_line_id.product_id.packaging_ids.mapped("qty"), default=1.0
+ )
- @api.depends('packaging_size', 'qty')
+ @api.onchange("qty")
def _compute_quantity_fits_packaging(self):
- for sale_order in self:
- order_lines = self.sale_max_qty_chooser.sale_max_qty_ids.filtered(lambda line: line.sale_line_id.product_id == sale_order.product_id)
- total_quantity = sum(order_lines.mapped('qty'))
- sale_order.quantity_fits_packaging = total_quantity % sale_order.packaging_size == 0
\ No newline at end of file
+ for max_qty_line in self:
+ order_lines = max_qty_line.sale_max_qty_chooser.sale_max_qty_ids.filtered(
+ lambda line: line.sale_line_id.product_id == max_qty_line.product_id
+ )
+ max_qty_line.total_quantity = sum(order_lines.mapped("qty"))
+ max_qty_line.quantity_fits_packaging = max_qty_line.total_quantity % max_qty_line.packaging_size == 0
+ # for order_line in order_lines:
+ # order_line.quantity_fits_packaging = max_qty_line.quantity_fits_packaging
+
+ @api.constrains("qty")
+ def _check_product_uom_qty(self):
+ for max_qty_line in self:
+ if max_qty_line.max_qty != 0 and max_qty_line.qty > max_qty_line.max_qty:
+ raise UserError(_("The quantity must be less than or equal to the maximum quantity."))
diff --git a/nfu_sale_product_min_max_qty/wizard/sale_max_qty_line_views.xml b/nfu_sale_product_min_max_qty/wizard/sale_max_qty_line_views.xml
new file mode 100644
index 0000000..67e32e6
--- /dev/null
+++ b/nfu_sale_product_min_max_qty/wizard/sale_max_qty_line_views.xml
@@ -0,0 +1,28 @@
+
+
+
+ sale.max.qty.line.search
+ sale.max.qty.line
+
+
+
+
+
+
+
+
+ sale.max.qty.line.tree
+ sale.max.qty.line
+
+
+
+
+
+
+
+
+
+
+
+
+