From b2d4830a777d765ec5fd283f90f0df0aeba04fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20G=C3=B6ttsch?= Date: Tue, 2 Jul 2024 19:40:01 +0200 Subject: [PATCH] [add] wizzard proto code TODO: add new models to security file --- nfu_sale_product_min_max_qty/README.rst | 10 +-- .../models/sale_order.py | 65 ++++++++++++++----- .../static/description/index.html | 3 +- .../views/sale_order_views.xml | 6 +- .../wizzard/sale_max_qty_chooser.py | 45 +++++++++++++ .../wizzard/sale_max_qty_line.py | 16 +++++ .../wizzard/sale_max_qty_line_views.xml | 40 ++++++++++++ 7 files changed, 160 insertions(+), 25 deletions(-) create mode 100644 nfu_sale_product_min_max_qty/wizzard/sale_max_qty_chooser.py create mode 100644 nfu_sale_product_min_max_qty/wizzard/sale_max_qty_line.py create mode 100644 nfu_sale_product_min_max_qty/wizzard/sale_max_qty_line_views.xml diff --git a/nfu_sale_product_min_max_qty/README.rst b/nfu_sale_product_min_max_qty/README.rst index f68c655..925bc7c 100644 --- a/nfu_sale_product_min_max_qty/README.rst +++ b/nfu_sale_product_min_max_qty/README.rst @@ -17,12 +17,12 @@ NFU Sale Min Max Quantitiy :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/bakeupboys/nfu/tree/16.0/nfu_sale_product_min_max_qty + :target: https://github.com/bruecksen/ife_nfu/tree/16.0/nfu_sale_product_min_max_qty :alt: bruecksen/ife_nfu |badge1| |badge2| |badge3| -This module adds a minium and a maximum order quantity field to Sale Orders and the Webshop. +This module adds a minium and a maximum order quantity field to Sale Orders and adds it to checkout of the website shop. **Table of contents** @@ -37,10 +37,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. @@ -61,6 +61,6 @@ Contributors Maintainers ~~~~~~~~~~~ -This module is part of the `bruecksen/ife_nfu `_ project on GitHub. +This module is part of the `bruecksen/ife_nfu `_ project on GitHub. You are welcome to contribute. 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 c8872f0..95e0821 100644 --- a/nfu_sale_product_min_max_qty/models/sale_order.py +++ b/nfu_sale_product_min_max_qty/models/sale_order.py @@ -1,12 +1,37 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import _, fields, models +from odoo import _, models class SaleOrder(models.Model): - _inherit = 'sale.order' + _inherit = "sale.order" 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({}) + + 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": .... + + }) + + 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", @@ -16,25 +41,33 @@ class SaleOrder(models.Model): } def _prepare_order_line_values( - self, product_id, quantity, linked_line_id=False, - no_variant_attribute_values=None, product_custom_attribute_values=None, + self, + product_id, + quantity, + linked_line_id=False, + no_variant_attribute_values=None, + product_custom_attribute_values=None, **kwargs ): - values = super()._prepare_order_line_values(product_id, quantity, linked_line_id=linked_line_id, no_variant_attribute_values=no_variant_attribute_values, product_custom_attribute_values=product_custom_attribute_values, **kwargs) - values.update({ - 'product_uom_min_qty': quantity, - 'product_uom_max_qty': kwargs.get('max_qty', quantity), - }) + values = super()._prepare_order_line_values( + product_id, + quantity, + linked_line_id=linked_line_id, + no_variant_attribute_values=no_variant_attribute_values, + product_custom_attribute_values=product_custom_attribute_values, + **kwargs + ) + values.update({"product_uom_min_qty": quantity, "product_uom_max_qty": kwargs.get("max_qty", quantity)}) return values - def _prepare_order_line_update_values( - self, order_line, quantity, linked_line_id=False, **kwargs - ): - values = super()._prepare_order_line_update_values(order_line, quantity, linked_line_id=linked_line_id, **kwargs) - max_qty = kwargs.get('max_qty', quantity) + def _prepare_order_line_update_values(self, order_line, quantity, linked_line_id=False, **kwargs): + values = super()._prepare_order_line_update_values( + order_line, quantity, linked_line_id=linked_line_id, **kwargs + ) + max_qty = kwargs.get("max_qty", quantity) if quantity != order_line.product_uom_min_qty: - values['product_uom_min_qty'] = quantity + values["product_uom_min_qty"] = quantity if max_qty and max_qty != order_line.product_uom_max_qty: - values['product_uom_max_qty'] = max_qty + values["product_uom_max_qty"] = max_qty return values diff --git a/nfu_sale_product_min_max_qty/static/description/index.html b/nfu_sale_product_min_max_qty/static/description/index.html index 9a46f09..4ab2ef6 100644 --- a/nfu_sale_product_min_max_qty/static/description/index.html +++ b/nfu_sale_product_min_max_qty/static/description/index.html @@ -370,7 +370,7 @@ ul.auto-toc { !! source digest: sha256:4dfaea54e4d01502b433eb5c0dcca409a5fbe2c3f175e29382a19230343183c9 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: LGPL-3 bruecksen/ife_nfu

-

This module adds a minium and a maximum order quantity field to Sale Orders

+

This module adds a minium and a maximum order quantity field to Sale Orders and adds it to checkout of the website shop.

Table of contents

diff --git a/nfu_sale_product_min_max_qty/views/sale_order_views.xml b/nfu_sale_product_min_max_qty/views/sale_order_views.xml index f4d294f..708ce24 100644 --- a/nfu_sale_product_min_max_qty/views/sale_order_views.xml +++ b/nfu_sale_product_min_max_qty/views/sale_order_views.xml @@ -14,13 +14,13 @@ sale.order.list.view.inherited sale.order - +
-
- \ No newline at end of file + diff --git a/nfu_sale_product_min_max_qty/wizzard/sale_max_qty_chooser.py b/nfu_sale_product_min_max_qty/wizzard/sale_max_qty_chooser.py new file mode 100644 index 0000000..dd0ec1d --- /dev/null +++ b/nfu_sale_product_min_max_qty/wizzard/sale_max_qty_chooser.py @@ -0,0 +1,45 @@ +from odoo import fields, models + + +class SaleMaxQtyChooser(models.TransientModel): + """Wizard to Allow user to adjust the sale order amout to fit to a packaging size""" + + _name = "sale.max.qty.chooser" + _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") + + def confirm_qty_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 + list or smalles package sale_order_line.product_id.product.packaging_ids.qty) + we can use write({'key':'value'}) to update all sale order lines and action_confirm() to validate all sale + orders + + Also see this methode on how to create new records. It creates a invoice with invoice lines. we need to do the + same for sale orders + + def action_sold(self): + res = super().action_sold() + self.env["account.move"].create( + { + "property_id": self.id, + "partner_id": self.buyer_id.id, + "move_type": "out_invoice", + "line_ids": [ + fields.Command.create( + { + "name": f"Property {self.name} - 10% Tax", + "quantity": 1, + "price_unit": self.selling_price * 1.1, + } + ), + fields.Command.create({"name": "Administration Fees", "quantity": 1, "price_unit": 1000}), + ], + } + ) + return res + """ diff --git a/nfu_sale_product_min_max_qty/wizzard/sale_max_qty_line.py b/nfu_sale_product_min_max_qty/wizzard/sale_max_qty_line.py new file mode 100644 index 0000000..8e64311 --- /dev/null +++ b/nfu_sale_product_min_max_qty/wizzard/sale_max_qty_line.py @@ -0,0 +1,16 @@ +from odoo import fields, models + + +class SaleMaxQtyLine(models.TransientModel): + """ + Lines to shown in Wizard + """ + + _name = "sale.max.qty.line" + _description = "Max qty Sale Order Lines" + + sale_max_qty_chooser = fields.Many2one("sale.max.qty.chooser") + qty = fields.Float() + sale_line_id = fields.Many2one("sale.order.line") + product_id = fields.Many2one(related="sale_line_id.product_id") + reset_to_draft = fields.Boolean() diff --git a/nfu_sale_product_min_max_qty/wizzard/sale_max_qty_line_views.xml b/nfu_sale_product_min_max_qty/wizzard/sale_max_qty_line_views.xml new file mode 100644 index 0000000..00bf228 --- /dev/null +++ b/nfu_sale_product_min_max_qty/wizzard/sale_max_qty_line_views.xml @@ -0,0 +1,40 @@ + + + + + Sale Max Quantity Chhooser + sale.max.qty.chooser + +
+
+

Headline

+
+ + + + + + + + +
+
+
+
+
+ + + Set Quantities + sale.max.qty.chooser + form + new + +