[imp] added basic wizard

TODO:
add return methode
This commit is contained in:
Niels Göttsch 2024-07-03 08:18:00 +02:00
parent 1bdf0f3c2f
commit 6ff1bbb45d
10 changed files with 39 additions and 43 deletions

View file

@ -1,2 +1,3 @@
from . import models
from . import controllers
from . import controllers
from . import wizard

View file

@ -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",
}

View file

@ -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,

View file

@ -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."))

View file

@ -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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_sale_max_qty_chooser sale.max.qty.chooser model_sale_max_qty_chooser sales_team.group_sale_salesman 1 1 1 1
3 access_sale_max_qty_line sale.max.qty.line model_sale_max_qty_line sales_team.group_sale_salesman 1 1 1 1

View file

@ -4,7 +4,7 @@
<field name="name">sale.order.line.tree</field>
<field name="model">sale.order.line</field>
<field name="arch" type="xml">
<tree string="Sales Order Lines" create="false">
<tree create="false">
<field name="order_id"/>
<field name="order_partner_id"/>
<field name="name"/>
@ -21,4 +21,4 @@
</tree>
</field>
</record>
</odoo>
</odoo>

View file

@ -0,0 +1,2 @@
from . import sale_max_qty_chooser
from . import sale_max_qty_line

View file

@ -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

View file

@ -11,7 +11,6 @@
</div>
<field name="sale_max_qty_ids">
<tree create="0">
<!-- Make this field read only -->
<field name="product_id"/>
<field name="qty"/>
<field name="reset_to_draft"/>
@ -19,7 +18,7 @@
</field>
<footer>
<button
name="confirm_qty_sale_order"
name="update_and_confirm_sale_order"
string="Confirm Sale Orders"
type="object"
class="btn-primary"