From 6ff1bbb45d45edd7b3b696fca1b3c532282cec0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20G=C3=B6ttsch?= Date: Wed, 3 Jul 2024 08:18:00 +0200 Subject: [PATCH] [imp] added basic wizard TODO: add return methode --- nfu_sale_product_min_max_qty/__init__.py | 3 +- nfu_sale_product_min_max_qty/__manifest__.py | 10 ++--- .../models/sale_order.py | 43 ++++++++----------- .../models/sale_order_line.py | 8 ++-- .../security/ir.model.access.csv | 3 ++ .../views/sale_order_line_views.xml | 4 +- .../wizard/__init__.py | 2 + .../sale_max_qty_chooser.py | 6 +-- .../sale_max_qty_chooser_views.xml} | 3 +- .../{wizzard => wizard}/sale_max_qty_line.py | 0 10 files changed, 39 insertions(+), 43 deletions(-) create mode 100644 nfu_sale_product_min_max_qty/security/ir.model.access.csv create mode 100644 nfu_sale_product_min_max_qty/wizard/__init__.py rename nfu_sale_product_min_max_qty/{wizzard => wizard}/sale_max_qty_chooser.py (90%) rename nfu_sale_product_min_max_qty/{wizzard/sale_max_qty_line_views.xml => wizard/sale_max_qty_chooser_views.xml} (92%) rename nfu_sale_product_min_max_qty/{wizzard => wizard}/sale_max_qty_line.py (100%) diff --git a/nfu_sale_product_min_max_qty/__init__.py b/nfu_sale_product_min_max_qty/__init__.py index 38718f0..48d9904 100644 --- a/nfu_sale_product_min_max_qty/__init__.py +++ b/nfu_sale_product_min_max_qty/__init__.py @@ -1,2 +1,3 @@ from . import models -from . import controllers \ No newline at end of file +from . import controllers +from . import wizard diff --git a/nfu_sale_product_min_max_qty/__manifest__.py b/nfu_sale_product_min_max_qty/__manifest__.py index 016b964..0733755 100644 --- a/nfu_sale_product_min_max_qty/__manifest__.py +++ b/nfu_sale_product_min_max_qty/__manifest__.py @@ -9,12 +9,10 @@ "data": [ "views/sale_order_views.xml", "views/sale_order_line_views.xml", - 'views/templates.xml', + "wizard/sale_max_qty_chooser_views.xml", + "views/templates.xml", + "security/ir.model.access.csv", ], - 'assets': { - "web.assets_frontend": [ - "nfu_sale_product_min_max_qty/static/src/js/website_sale.js" - ] - }, + "assets": {"web.assets_frontend": ["nfu_sale_product_min_max_qty/static/src/js/website_sale.js"]}, "license": "LGPL-3", } 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 95e0821..23b1a50 100644 --- a/nfu_sale_product_min_max_qty/models/sale_order.py +++ b/nfu_sale_product_min_max_qty/models/sale_order.py @@ -1,5 +1,3 @@ -# Part of Odoo. See LICENSE file for full copyright and licensing details. - from odoo import _, models @@ -9,36 +7,31 @@ class SaleOrder(models.Model): def action_min_max_qty_wizard(self): """ Here you need to create the wizzard objects first and then call the wizzard with the newly created id - - sale_order_lines = self.env[sale.order.line].search[id in self.order_line.ids] - + """ sale_max_qty_chooser = self.env["sale.max.qty.chooser"].create({}) + draft_sale_orders = self.filtered(lambda x: x.state == "draft") + for sale_order in draft_sale_orders: + sale_order_lines = self.env["sale.order.line"].search([("id", "in", sale_order.order_line.ids)]) - for line in sale_order_lines: - if not display_type: - sale_max_qty_line = self.env["sale.max.qty.line"].create({"sale_line_id": self.id, - "sale_max_qty_chooser": sale_max_qty_chooser, - "qty": .... - - }) + for line in sale_order_lines: + if not line.display_type: + self.env["sale.max.qty.line"].create( + { + "sale_line_id": line.id, + "sale_max_qty_chooser": sale_max_qty_chooser.id, + "qty": line.product_uom_qty, + } + ) 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, - } - return action - """ - return { "name": _("Min max qty wizard"), "type": "ir.actions.act_window", - "res_model": "sale.order.line", - "view_mode": "tree,form", - "domain": [("id", "in", self.order_line.ids)], + "res_model": "sale.max.qty.chooser", + "view_mode": "form", + "target": "new", + "res_id": sale_max_qty_chooser.id, } + return action def _prepare_order_line_values( self, diff --git a/nfu_sale_product_min_max_qty/models/sale_order_line.py b/nfu_sale_product_min_max_qty/models/sale_order_line.py index 18dde7d..b8d42a6 100644 --- a/nfu_sale_product_min_max_qty/models/sale_order_line.py +++ b/nfu_sale_product_min_max_qty/models/sale_order_line.py @@ -1,5 +1,5 @@ -from odoo import models, fields, api -from odoo.exceptions import ValidationError +from odoo import _, api, fields, models +from odoo.exceptions import UserError class SaleOrderLine(models.Model): @@ -11,5 +11,5 @@ 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_qty > record.product_uom_max_qty: - raise ValidationError("The quantity must be less than or equal to the maximum quantity.") + 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.")) diff --git a/nfu_sale_product_min_max_qty/security/ir.model.access.csv b/nfu_sale_product_min_max_qty/security/ir.model.access.csv new file mode 100644 index 0000000..04aeaf3 --- /dev/null +++ b/nfu_sale_product_min_max_qty/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_sale_max_qty_chooser,sale.max.qty.chooser,model_sale_max_qty_chooser,sales_team.group_sale_salesman,1,1,1,1 +access_sale_max_qty_line,sale.max.qty.line,model_sale_max_qty_line,sales_team.group_sale_salesman,1,1,1,1 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 c8768e4..6429131 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 - + @@ -21,4 +21,4 @@ - \ No newline at end of file + diff --git a/nfu_sale_product_min_max_qty/wizard/__init__.py b/nfu_sale_product_min_max_qty/wizard/__init__.py new file mode 100644 index 0000000..236a111 --- /dev/null +++ b/nfu_sale_product_min_max_qty/wizard/__init__.py @@ -0,0 +1,2 @@ +from . import sale_max_qty_chooser +from . import sale_max_qty_line diff --git a/nfu_sale_product_min_max_qty/wizzard/sale_max_qty_chooser.py b/nfu_sale_product_min_max_qty/wizard/sale_max_qty_chooser.py similarity index 90% rename from nfu_sale_product_min_max_qty/wizzard/sale_max_qty_chooser.py rename to nfu_sale_product_min_max_qty/wizard/sale_max_qty_chooser.py index dd0ec1d..4246ccc 100644 --- a/nfu_sale_product_min_max_qty/wizzard/sale_max_qty_chooser.py +++ b/nfu_sale_product_min_max_qty/wizard/sale_max_qty_chooser.py @@ -8,10 +8,10 @@ class SaleMaxQtyChooser(models.TransientModel): _description = "Sale Max Quantity Chhooser" # fill from init or compute from given sale order lines - sale_order_ids = fields.Many2many("sale.order") - sale_max_qty_ids = fields.One2many("sale.max.qty.line", "mrp_return_id") + # sale_order_ids = fields.Many2many("sale.order") + sale_max_qty_ids = fields.One2many("sale.max.qty.line", "sale_max_qty_chooser") - def confirm_qty_sale_order(self): + def update_and_confirm_sale_order(self): """ Confirm sale orders where the quantity is fine. Create new Sale Orders for SO Lines with reset to draft Through user error when total order amount of a product is not equal to packaging size (first package in the diff --git a/nfu_sale_product_min_max_qty/wizzard/sale_max_qty_line_views.xml b/nfu_sale_product_min_max_qty/wizard/sale_max_qty_chooser_views.xml similarity index 92% rename from nfu_sale_product_min_max_qty/wizzard/sale_max_qty_line_views.xml rename to nfu_sale_product_min_max_qty/wizard/sale_max_qty_chooser_views.xml index 00bf228..89da727 100644 --- a/nfu_sale_product_min_max_qty/wizzard/sale_max_qty_line_views.xml +++ b/nfu_sale_product_min_max_qty/wizard/sale_max_qty_chooser_views.xml @@ -11,7 +11,6 @@ - @@ -19,7 +18,7 @@