Initial commit: Mrp packages

This commit is contained in:
Ernad Husremovic 2025-08-29 15:20:50 +02:00
commit 50d736b3bd
739 changed files with 538193 additions and 0 deletions

View file

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import stock_picking_return
from . import mrp_consumption_warning
from . import change_production_qty

View file

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models
class ChangeProductionQty(models.TransientModel):
_inherit = 'change.production.qty'
@api.model
def _need_quantity_propagation(self, move, qty):
res = super()._need_quantity_propagation(move, qty)
return res and not any(m.is_subcontract for m in move.move_dest_ids)
@api.model
def _update_product_qty(self, move, qty):
res = super()._update_product_qty(move, qty)
subcontract_moves = move.move_dest_ids.filtered(lambda m: m.is_subcontract and m.from_immediate_transfer)
if subcontract_moves:
subcontract_moves[0].with_context(cancel_backorder=False).write({'product_uom_qty': subcontract_moves[0].product_uom_qty + qty})
return res

View file

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
class MrpConsumptionWarning(models.TransientModel):
_inherit = 'mrp.consumption.warning'
def action_confirm(self):
if self.mrp_production_ids._get_subcontract_move():
return self.mrp_production_ids.with_context(skip_consumption=True).subcontracting_record_component()
return super().action_confirm()
def action_cancel(self):
mo_subcontracted_move = self.mrp_production_ids._get_subcontract_move()
if mo_subcontracted_move:
return mo_subcontracted_move.filtered(lambda move: move.state not in ('done', 'cancel'))._action_record_components()
return super().action_cancel()

View file

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models, fields
class ReturnPicking(models.TransientModel):
_inherit = 'stock.return.picking'
subcontract_location_id = fields.Many2one('stock.location', compute='_compute_subcontract_location_id')
@api.depends('picking_id')
def _compute_subcontract_location_id(self):
for record in self:
record.subcontract_location_id = record.picking_id.partner_id.with_company(
record.picking_id.company_id
).property_stock_subcontractor
@api.onchange('picking_id')
def _onchange_picking_id(self):
res = super(ReturnPicking, self)._onchange_picking_id()
if any(return_line.quantity > 0 and return_line.move_id.is_subcontract for return_line in self.product_return_moves):
self.location_id = self.picking_id.partner_id.with_company(self.picking_id.company_id).property_stock_subcontractor
return res
def _prepare_move_default_values(self, return_line, new_picking):
vals = super(ReturnPicking, self)._prepare_move_default_values(return_line, new_picking)
vals['is_subcontract'] = False
return vals

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_stock_return_picking_form_subcontracting" model="ir.ui.view">
<field name="name">Return lines</field>
<field name="model">stock.return.picking</field>
<field name="inherit_id" ref="stock.view_stock_return_picking_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='location_id']" position="before">
<field name="subcontract_location_id" invisible="1"/>
<field name="original_location_id" invisible="1"/>
</xpath>
<xpath expr="//field[@name='location_id']" position="attributes">
<attribute name="domain">
['|', '|', ('id', '=', original_location_id), ('return_location', '=', True), ('id', '=', subcontract_location_id)]
</attribute>
</xpath>
</field>
</record>
</odoo>