19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:31:47 +01:00
parent accf5918df
commit 6e65e8c877
688 changed files with 225434 additions and 199401 deletions

View file

@ -2,3 +2,5 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import repair
from . import production
from . import stock_move

View file

@ -0,0 +1,34 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, _
class MrpProduction(models.Model):
_inherit = 'mrp.production'
repair_count = fields.Integer(
string='Count of source repairs',
compute='_compute_repair_count',
groups='stock.group_stock_user',
)
@api.depends('move_dest_ids.repair_id')
def _compute_repair_count(self):
for production in self:
production.repair_count = len(production.move_dest_ids.repair_id)
def action_view_repair_orders(self):
self.ensure_one()
repair_ids = self.move_dest_ids.repair_id
action = {
'type': 'ir.actions.act_window',
'res_model': 'repair.order',
'views': [[False, 'form']],
}
if self.repair_count == 1:
action['res_id'] = repair_ids.id
elif self.repair_count > 1:
action['name'] = _("Repair Source of %s", self.name)
action['views'] = [[False, 'list']]
action['domain'] = [('id', 'in', repair_ids.ids)]
return action

View file

@ -1,11 +1,22 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models
from odoo import api, fields, models, _
class Repair(models.Model):
class RepairOrder(models.Model):
_inherit = 'repair.order'
production_count = fields.Integer(
'Count of MOs generated',
compute='_compute_production_count',
groups='mrp.group_mrp_user',
)
@api.depends('reference_ids.production_ids')
def _compute_production_count(self):
for repair in self:
repair.production_count = len(repair.reference_ids.production_ids)
@api.model_create_multi
def create(self, vals_list):
orders = super().create(vals_list)
@ -20,7 +31,7 @@ class Repair(models.Model):
def action_explode(self):
lines_to_unlink_ids = set()
line_vals_list = []
for op in self.operations:
for op in self.move_ids:
bom = self.env['mrp.bom'].sudo()._bom_find(op.product_id, company_id=op.company_id.id, bom_type='phantom')[op.product_id]
if not bom:
continue
@ -31,35 +42,50 @@ class Repair(models.Model):
line_vals_list.append(op._prepare_phantom_line_vals(bom_line, line_data['qty']))
lines_to_unlink_ids.add(op.id)
self.env['repair.line'].browse(lines_to_unlink_ids).sudo().unlink()
self.env['stock.move'].browse(lines_to_unlink_ids).sudo().unlink()
if line_vals_list:
self.env['repair.line'].create(line_vals_list)
self.env['stock.move'].create(line_vals_list)
def action_view_mrp_productions(self):
self.ensure_one()
production_order_ids = self.reference_ids.production_ids
action = {
'type': 'ir.actions.act_window',
'res_model': 'mrp.production',
'views': [[False, 'form']],
}
if self.production_count == 1:
action['res_id'] = production_order_ids.id
elif self.production_count > 1:
action['name'] = _("Manufacturing Orders generated by %s", self.name)
action['views'] = [[False, 'list']]
action['domain'] = [('id', 'in', production_order_ids.ids)]
return action
def _get_action_add_from_catalog_extra_context(self):
bom = self.env['mrp.bom']._bom_find(self.product_id, company_id=self.company_id.id)[self.product_id]
product_ids = [line.product_id.id for line in bom.bom_line_ids] if bom else []
return {
**super()._get_action_add_from_catalog_extra_context(),
'catalog_bom_product_ids': product_ids,
'search_default_bom_parts': bool(product_ids)
}
class RepairLine(models.Model):
_inherit = 'repair.line'
class StockMove(models.Model):
_inherit = 'stock.move'
def _prepare_phantom_line_vals(self, bom_line, qty):
self.ensure_one()
product = bom_line.product_id
uom = bom_line.product_uom_id
partner = self.repair_id.partner_id
price = self.repair_id.pricelist_id._get_product_price(product, qty, uom=uom)
tax = self.env['account.tax']
if partner:
partner_invoice = self.repair_id.partner_invoice_id or partner
fpos = self.env['account.fiscal.position']._get_fiscal_position(partner_invoice, delivery=self.repair_id.address_id)
taxes = self.product_id.taxes_id.filtered(lambda x: x.company_id == self.repair_id.company_id)
tax = fpos.map_tax(taxes)
return {
'name': self.name,
'repair_id': self.repair_id.id,
'type': self.type,
'repair_line_type': self.repair_line_type,
'product_id': product.id,
'price_unit': price,
'tax_id': [(4, t.id) for t in tax],
'price_unit': self.price_unit,
'product_uom_qty': qty,
'product_uom': uom.id,
'location_id': self.location_id.id,
'location_dest_id': self.location_dest_id.id,
'state': 'draft',

View file

@ -0,0 +1,11 @@
from odoo import models
class StockMove(models.Model):
_inherit = 'stock.move'
def _prepare_phantom_move_values(self, bom_line, product_qty, quantity_done):
vals = super()._prepare_phantom_move_values(bom_line, product_qty, quantity_done)
if self.repair_id:
vals['repair_id'] = self.repair_id.id
return vals