mirror of
https://github.com/bringout/oca-ocb-mrp.git
synced 2026-04-24 22:12:07 +02:00
19.0 vanilla
This commit is contained in:
parent
accf5918df
commit
6e65e8c877
688 changed files with 225434 additions and 199401 deletions
|
|
@ -2,7 +2,7 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, Command
|
||||
from odoo.tools import float_round, float_compare
|
||||
from odoo.tools import float_round
|
||||
|
||||
|
||||
class MrpProductionSplitMulti(models.TransientModel):
|
||||
|
|
@ -22,40 +22,45 @@ class MrpProductionSplit(models.TransientModel):
|
|||
product_qty = fields.Float(related='production_id.product_qty')
|
||||
product_uom_id = fields.Many2one(related='production_id.product_uom_id')
|
||||
production_capacity = fields.Float(related='production_id.production_capacity')
|
||||
counter = fields.Integer(
|
||||
"Split #", default=0, compute="_compute_counter",
|
||||
store=True, readonly=False)
|
||||
production_detailed_vals_ids = fields.One2many(
|
||||
'mrp.production.split.line', 'mrp_production_split_id',
|
||||
'Split Details', compute="_compute_details", store=True, readonly=False)
|
||||
valid_details = fields.Boolean("Valid", compute="_compute_valid_details")
|
||||
max_batch_size = fields.Float("Max Batch Size", compute="_compute_max_batch_size", digits='Product Unit', readonly=False)
|
||||
num_splits = fields.Integer("# Splits", compute="_compute_num_splits", readonly=True)
|
||||
|
||||
@api.depends('production_detailed_vals_ids')
|
||||
def _compute_counter(self):
|
||||
@api.depends('production_id')
|
||||
def _compute_max_batch_size(self):
|
||||
for wizard in self:
|
||||
wizard.counter = len(wizard.production_detailed_vals_ids)
|
||||
bom_id = wizard.production_id.bom_id
|
||||
wizard.max_batch_size = bom_id.batch_size if bom_id.enable_batch_size else wizard.product_qty
|
||||
|
||||
@api.depends('counter')
|
||||
@api.depends('max_batch_size')
|
||||
def _compute_num_splits(self):
|
||||
self.num_splits = 0
|
||||
for wizard in self:
|
||||
if wizard.product_uom_id.compare(wizard.max_batch_size, 0) > 0:
|
||||
wizard.num_splits = float_round(
|
||||
wizard.product_qty / wizard.max_batch_size,
|
||||
precision_digits=0,
|
||||
rounding_method='UP')
|
||||
|
||||
@api.depends('num_splits')
|
||||
def _compute_details(self):
|
||||
for wizard in self:
|
||||
commands = [Command.clear()]
|
||||
if wizard.counter < 1 or not wizard.production_id:
|
||||
if wizard.num_splits <= 0 or not wizard.production_id:
|
||||
wizard.production_detailed_vals_ids = commands
|
||||
continue
|
||||
quantity = float_round(wizard.product_qty / wizard.counter, precision_rounding=wizard.product_uom_id.rounding)
|
||||
remaining_quantity = wizard.product_qty
|
||||
for _ in range(wizard.counter - 1):
|
||||
remaining_qty = wizard.product_qty
|
||||
for _ in range(wizard.num_splits):
|
||||
qty = min(wizard.max_batch_size, remaining_qty)
|
||||
commands.append(Command.create({
|
||||
'quantity': quantity,
|
||||
'user_id': wizard.production_id.user_id,
|
||||
'date': wizard.production_id.date_planned_start,
|
||||
'quantity': qty,
|
||||
'user_id': wizard.production_id.user_id.id,
|
||||
'date': wizard.production_id.date_start,
|
||||
}))
|
||||
remaining_quantity = float_round(remaining_quantity - quantity, precision_rounding=wizard.product_uom_id.rounding)
|
||||
commands.append(Command.create({
|
||||
'quantity': remaining_quantity,
|
||||
'user_id': wizard.production_id.user_id,
|
||||
'date': wizard.production_id.date_planned_start,
|
||||
}))
|
||||
remaining_qty = wizard.product_uom_id.round(remaining_qty - qty)
|
||||
wizard.production_detailed_vals_ids = commands
|
||||
|
||||
@api.depends('production_detailed_vals_ids')
|
||||
|
|
@ -63,13 +68,13 @@ class MrpProductionSplit(models.TransientModel):
|
|||
self.valid_details = False
|
||||
for wizard in self:
|
||||
if wizard.production_detailed_vals_ids:
|
||||
wizard.valid_details = float_compare(wizard.product_qty, sum(wizard.production_detailed_vals_ids.mapped('quantity')), precision_rounding=wizard.product_uom_id.rounding) == 0
|
||||
wizard.valid_details = wizard.product_uom_id.compare(wizard.product_qty, sum(wizard.production_detailed_vals_ids.mapped('quantity'))) == 0
|
||||
|
||||
def action_split(self):
|
||||
productions = self.production_id._split_productions({self.production_id: [detail.quantity for detail in self.production_detailed_vals_ids]})
|
||||
for production, detail in zip(productions, self.production_detailed_vals_ids):
|
||||
production.user_id = detail.user_id
|
||||
production.date_planned_start = detail.date
|
||||
production.date_start = detail.date
|
||||
if self.production_split_multi_id:
|
||||
saved_production_split_multi_id = self.production_split_multi_id.id
|
||||
self.production_split_multi_id.production_ids = [Command.unlink(self.id)]
|
||||
|
|
@ -84,7 +89,7 @@ class MrpProductionSplit(models.TransientModel):
|
|||
|
||||
def action_return_to_list(self):
|
||||
self.production_detailed_vals_ids = [Command.clear()]
|
||||
self.counter = 0
|
||||
self.max_batch_size = 0
|
||||
action = self.env['ir.actions.actions']._for_xml_id('mrp.action_mrp_production_split_multi')
|
||||
action['res_id'] = self.production_split_multi_id.id
|
||||
return action
|
||||
|
|
@ -96,8 +101,8 @@ class MrpProductionSplitLine(models.TransientModel):
|
|||
|
||||
mrp_production_split_id = fields.Many2one(
|
||||
'mrp.production.split', 'Split Production', required=True, ondelete="cascade")
|
||||
quantity = fields.Float('Quantity To Produce', digits='Product Unit of Measure', required=True)
|
||||
quantity = fields.Float('Quantity To Produce', digits='Product Unit', required=True)
|
||||
user_id = fields.Many2one(
|
||||
'res.users', 'Responsible',
|
||||
domain=lambda self: [('groups_id', 'in', self.env.ref('mrp.group_mrp_user').id)])
|
||||
domain=lambda self: [('all_group_ids', 'in', self.env.ref('mrp.group_mrp_user').id)])
|
||||
date = fields.Datetime('Schedule Date')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue