[wip] changed wizzard to use only sale_order_lines
TODO: Onchange has to recompute all record of the recordset and not only itself
This commit is contained in:
parent
ea416d2aa6
commit
1e21f38099
6 changed files with 75 additions and 23 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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)],
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 create="false">
|
||||
<tree create="false" expand="1">
|
||||
<field name="order_id"/>
|
||||
<field name="order_partner_id"/>
|
||||
<field name="name"/>
|
||||
|
|
|
|||
|
|
@ -1,24 +1,23 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_sale_max_qty_chooser_form" model="ir.ui.view">
|
||||
<field name="name">Sale Max Quantity Chhooser</field>
|
||||
<field name="model">sale.max.qty.chooser</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<div class="oe_grey">
|
||||
<p>Headline</p>
|
||||
<p>Sale Orders</p>
|
||||
<field name="sale_order_ids" widget="many2many_tags"/>
|
||||
</div>
|
||||
<field name="sale_max_qty_ids">
|
||||
<tree create="0" editable="1">
|
||||
<field name="product_id"/>
|
||||
<field name="sale_max_qty_ids" context="{'search_default_group_by_qty': 1}">
|
||||
<!-- <tree create="0" editable="1" default_order="product_id">
|
||||
<field name="product_id" context="{'group_by': 'product_id'}" />
|
||||
<field name="qty"/>
|
||||
<field name="max_qty"/>
|
||||
<field name="packaging_size"/>
|
||||
<field name="quantity_fits_packaging" widget="boolean"/>
|
||||
<field name="reset_to_draft"/>
|
||||
</tree>
|
||||
</tree> -->
|
||||
</field>
|
||||
<footer>
|
||||
<button
|
||||
|
|
@ -38,6 +37,11 @@
|
|||
<field name="name">Set Quantities</field>
|
||||
<field name="res_model">sale.max.qty.chooser</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="target">current</field>
|
||||
<field name="context">
|
||||
{
|
||||
'search_default_group_by_product': 1,
|
||||
}
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
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."))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="view_sale_max_qty_line_search" model="ir.ui.view">
|
||||
<field name="name">sale.max.qty.line.search</field>
|
||||
<field name="model">sale.max.qty.line</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<filter string="Product" name="group_by_product" context="{'group_by':'product_id'}"/>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="viw_sale_max_qty_line_tree" model="ir.ui.view">
|
||||
<field name="name">sale.max.qty.line.tree</field>
|
||||
<field name="model">sale.max.qty.line</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree editable="bottom" create="0" expand="1">
|
||||
<field name="product_id"/>
|
||||
<field name="qty"/>
|
||||
<field name="max_qty"/>
|
||||
<field name="packaging_size"/>
|
||||
<field name="quantity_fits_packaging" widget="boolean"/>
|
||||
<field name="reset_to_draft"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Loading…
Reference in a new issue