Add packaging and calculate qty fitting
This commit is contained in:
parent
6ff1bbb45d
commit
92869e7e7f
5 changed files with 47 additions and 14 deletions
|
|
@ -11,17 +11,15 @@ class SaleOrder(models.Model):
|
|||
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 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,
|
||||
}
|
||||
)
|
||||
sale_max_qty_chooser.sale_order_ids += sale_order
|
||||
for line in sale_order.order_line.filtered(lambda x: not x.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"),
|
||||
|
|
@ -33,6 +31,18 @@ class SaleOrder(models.Model):
|
|||
}
|
||||
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
|
||||
"""
|
||||
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)],
|
||||
}
|
||||
|
||||
def _prepare_order_line_values(
|
||||
self,
|
||||
product_id,
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
<xpath expr="//tree" position="inside">
|
||||
<header>
|
||||
<button type="object" name="action_min_max_qty_wizard" string="Min/Max Wizard"/>
|
||||
<button type="object" name="action_sale_order_lines" string="Sale order lines"/>
|
||||
</header>
|
||||
</xpath>
|
||||
</field>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ 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_order_ids = fields.Many2many("sale.order")
|
||||
sale_max_qty_ids = fields.One2many("sale.max.qty.line", "sale_max_qty_chooser")
|
||||
|
||||
def update_and_confirm_sale_order(self):
|
||||
|
|
|
|||
|
|
@ -8,11 +8,15 @@
|
|||
<form>
|
||||
<div class="oe_grey">
|
||||
<p>Headline</p>
|
||||
<field name="sale_order_ids" widget="many2many_tags"/>
|
||||
</div>
|
||||
<field name="sale_max_qty_ids">
|
||||
<tree create="0">
|
||||
<tree create="0" editable="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>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from odoo import fields, models
|
||||
from odoo import fields, models, api
|
||||
|
||||
|
||||
class SaleMaxQtyLine(models.TransientModel):
|
||||
|
|
@ -11,6 +11,24 @@ class SaleMaxQtyLine(models.TransientModel):
|
|||
|
||||
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')
|
||||
|
||||
sale_line_id = fields.Many2one("sale.order.line")
|
||||
product_id = fields.Many2one(related="sale_line_id.product_id")
|
||||
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)
|
||||
|
||||
@api.depends('packaging_size', 'qty')
|
||||
def _compute_quantity_fits_packaging(self):
|
||||
for sale_order in self:
|
||||
order_lines = self.env['sale.max.qty.line'].search([
|
||||
('product_id', '=', sale_order.product_id.id),
|
||||
('sale_max_qty_chooser', '=', sale_order.sale_max_qty_chooser.id),
|
||||
])
|
||||
total_quantity = sum(order_lines.mapped('qty'))
|
||||
sale_order.quantity_fits_packaging = total_quantity % sale_order.packaging_size == 0
|
||||
Loading…
Reference in a new issue