[IMP] stock, mrp: company dependant scrap orders.
This commit adds fields 'company_id' on stock.scrap model. The company will filter locations and stock moves linked to the scrap document. We add also a specific sequence by company. Task-1930055 closes odoo/odoo#30498 Signed-off-by: Simon Lejeune (sle) <sle@openerp.com>
This commit is contained in:
committed by
William Henrotin
parent
b4f45e1fa2
commit
fa5037650d
@@ -891,6 +891,7 @@ class MrpProduction(models.Model):
|
||||
'type': 'ir.actions.act_window',
|
||||
'context': {'default_production_id': self.id,
|
||||
'product_ids': (self.move_raw_ids.filtered(lambda x: x.state not in ('done', 'cancel')) | self.move_finished_ids.filtered(lambda x: x.state == 'done')).mapped('product_id').ids,
|
||||
'default_company_id': self.company_id.id
|
||||
},
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
@@ -554,8 +554,10 @@ class MrpWorkorder(models.Model):
|
||||
'res_model': 'stock.scrap',
|
||||
'view_id': self.env.ref('stock.stock_scrap_form_view2').id,
|
||||
'type': 'ir.actions.act_window',
|
||||
'context': {'default_workorder_id': self.id, 'default_production_id': self.production_id.id, 'product_ids': (self.production_id.move_raw_ids.filtered(lambda x: x.state not in ('done', 'cancel')) | self.production_id.move_finished_ids.filtered(lambda x: x.state == 'done')).mapped('product_id').ids},
|
||||
# 'context': {'product_ids': self.move_raw_ids.filtered(lambda x: x.state not in ('done', 'cancel')).mapped('product_id').ids + [self.production_id.product_id.id]},
|
||||
'context': {'default_company_id': self.production_id.company_id.id,
|
||||
'default_workorder_id': self.id,
|
||||
'default_production_id': self.production_id.id,
|
||||
'product_ids': (self.production_id.move_raw_ids.filtered(lambda x: x.state not in ('done', 'cancel')) | self.production_id.move_finished_ids.filtered(lambda x: x.state == 'done')).mapped('product_id').ids},
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<field name="inherit_id" ref="stock.stock_scrap_form_view2"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="owner_id" position="after">
|
||||
<field name="workorder_id" attrs="{'invisible': [('workorder_id', '=', False)]}"/>
|
||||
<field name="production_id" attrs="{'invisible': [('production_id', '=', False)]}"/>
|
||||
<field name="workorder_id" domain="[('production_id', '=', production_id)]" attrs="{'invisible': [('workorder_id', '=', False)]}"/>
|
||||
<field name="production_id" domain="[('company_id', '=', company_id)]" attrs="{'invisible': [('production_id', '=', False)]}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
@@ -17,8 +17,8 @@
|
||||
<field name="inherit_id" ref="stock.stock_scrap_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="owner_id" position="after">
|
||||
<field name="workorder_id" attrs="{'invisible': [('workorder_id', '=', False)]}"/>
|
||||
<field name="production_id" attrs="{'invisible': [('production_id', '=', False)]}"/>
|
||||
<field name="workorder_id" domain="[('production_id', '=', product_id)]" attrs="{'invisible': [('workorder_id', '=', False)]}"/>
|
||||
<field name="production_id" domain="[('company_id', '=', company_id)]" attrs="{'invisible': [('production_id', '=', False)]}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -102,15 +102,6 @@
|
||||
<field name="company_id"></field>
|
||||
</record>
|
||||
|
||||
<record id="sequence_stock_scrap" model="ir.sequence">
|
||||
<field name="name">Scrap</field>
|
||||
<field name="code">stock.scrap</field>
|
||||
<field name="prefix">SP/</field>
|
||||
<field name="padding">5</field>
|
||||
<field name="number_next">1</field>
|
||||
<field name="number_increment">1</field>
|
||||
</record>
|
||||
|
||||
<!-- create xml ids for demo data that are widely used in tests or in other codes, for more convenience -->
|
||||
<function model="ir.model.data" name="_update_xmlids">
|
||||
<value model="base" eval="[{
|
||||
@@ -150,5 +141,6 @@
|
||||
<function model="res.company" name="create_missing_inventory_loss_location"/>
|
||||
<function model="res.company" name="create_missing_production_location"/>
|
||||
<function model="res.company" name="create_missing_scrap_location"/>
|
||||
<function model="res.company" name="create_missing_scrap_sequence"/>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
@@ -77,6 +77,21 @@ class Company(models.Model):
|
||||
'scrap_location': True,
|
||||
})
|
||||
|
||||
def _create_scrap_sequence(self):
|
||||
scrap_vals = []
|
||||
for company in self:
|
||||
scrap_vals.append({
|
||||
'name': '%s Sequence scrap' % company.name,
|
||||
'code': 'stock.scrap',
|
||||
'company_id': company.id,
|
||||
'prefix': 'SP/',
|
||||
'padding': 5,
|
||||
'number_next': 1,
|
||||
'number_increment': 1
|
||||
})
|
||||
if scrap_vals:
|
||||
self.env['ir.sequence'].create(scrap_vals)
|
||||
|
||||
@api.model
|
||||
def create_missing_warehouse(self):
|
||||
""" This hook is used to add a warehouse on existing companies
|
||||
@@ -125,6 +140,13 @@ class Company(models.Model):
|
||||
for company in company_without_property:
|
||||
company._create_scrap_location()
|
||||
|
||||
@api.model
|
||||
def create_missing_scrap_sequence(self):
|
||||
company_ids = self.env['res.company'].search([])
|
||||
company_has_scrap_seq = self.env['ir.sequence'].search([('code', '=', 'stock.scrap')]).mapped('company_id')
|
||||
company_todo_sequence = company_ids - company_has_scrap_seq
|
||||
company_todo_sequence._create_scrap_sequence()
|
||||
|
||||
def _create_per_company_locations(self):
|
||||
self.ensure_one()
|
||||
self._create_transit_location()
|
||||
@@ -132,9 +154,14 @@ class Company(models.Model):
|
||||
self._create_production_location()
|
||||
self._create_scrap_location()
|
||||
|
||||
def _create_per_company_sequences(self):
|
||||
self.ensure_one()
|
||||
self._create_scrap_sequence()
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
company = super(Company, self).create(vals)
|
||||
company.sudo()._create_per_company_locations()
|
||||
company.sudo()._create_per_company_sequences()
|
||||
self.env['stock.warehouse'].sudo().create({'name': company.name, 'code': company.name[:5], 'company_id': company.id, 'partner_id': company.partner_id.id})
|
||||
return company
|
||||
|
||||
@@ -1093,7 +1093,7 @@ class Picking(models.Model):
|
||||
'view_id': view.id,
|
||||
'views': [(view.id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'context': {'default_picking_id': self.id, 'product_ids': products.ids},
|
||||
'context': {'default_picking_id': self.id, 'product_ids': products.ids, 'default_company_id': self.company_id.id},
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ class StockScrap(models.Model):
|
||||
'Reference', default=lambda self: _('New'),
|
||||
copy=False, readonly=True, required=True,
|
||||
states={'done': [('readonly', True)]})
|
||||
company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company, required=True, readonly=True)
|
||||
origin = fields.Char(string='Source Document')
|
||||
product_id = fields.Many2one(
|
||||
'product.product', 'Product', domain=[('type', 'in', ['product', 'consu'])],
|
||||
@@ -39,16 +40,17 @@ class StockScrap(models.Model):
|
||||
states={'done': [('readonly', True)]}, domain="[('product_id', '=', product_id)]")
|
||||
package_id = fields.Many2one(
|
||||
'stock.quant.package', 'Package',
|
||||
states={'done': [('readonly', True)]})
|
||||
states={'done': [('readonly', True)]},
|
||||
domain="[('company_id', '=', company_id)]")
|
||||
owner_id = fields.Many2one('res.partner', 'Owner', states={'done': [('readonly', True)]})
|
||||
move_id = fields.Many2one('stock.move', 'Scrap Move', readonly=True)
|
||||
picking_id = fields.Many2one('stock.picking', 'Picking', states={'done': [('readonly', True)]})
|
||||
picking_id = fields.Many2one('stock.picking', 'Picking', states={'done': [('readonly', True)]}, domain="[('company_id', '=', company_id)]")
|
||||
location_id = fields.Many2one(
|
||||
'stock.location', 'Location', domain="[('usage', '=', 'internal')]",
|
||||
'stock.location', 'Location', domain="[('usage', '=', 'internal'), ('company_id', 'in', [company_id, False])]",
|
||||
required=True, states={'done': [('readonly', True)]}, default=_get_default_location_id)
|
||||
scrap_location_id = fields.Many2one(
|
||||
'stock.location', 'Scrap Location', default=_get_default_scrap_location_id,
|
||||
domain="[('scrap_location', '=', True)]", required=True, states={'done': [('readonly', True)]})
|
||||
domain="[('scrap_location', '=', True), ('company_id', 'in', [company_id, False])]", required=True, states={'done': [('readonly', True)]})
|
||||
scrap_qty = fields.Float('Quantity', default=1.0, required=True, states={'done': [('readonly', True)]})
|
||||
state = fields.Selection([
|
||||
('draft', 'Draft'),
|
||||
@@ -93,6 +95,7 @@ class StockScrap(models.Model):
|
||||
return {
|
||||
'name': self.name,
|
||||
'origin': self.origin or self.picking_id.name or self.name,
|
||||
'company_id': self.company_id.id,
|
||||
'product_id': self.product_id.id,
|
||||
'product_uom': self.product_uom_id.id,
|
||||
'product_uom_qty': self.scrap_qty,
|
||||
|
||||
@@ -164,5 +164,13 @@
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.rule" id="stock_scrap_company_rule">
|
||||
<field name="name">stock_scrap_company multi-company</field>
|
||||
<field name="model_id" ref="model_stock_scrap"/>
|
||||
<field name="global" eval="True"/>
|
||||
<field name="domain_force">[('company_id', 'in', company_ids)]</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
@@ -53,15 +53,16 @@
|
||||
</div>
|
||||
</group>
|
||||
<group>
|
||||
<field name="lot_id" attrs="{'invisible': [('tracking', '=', 'none')], 'required': [('tracking', '!=', 'none')]}" groups="stock.group_production_lot"/>
|
||||
<field name="lot_id" attrs="{'invisible': [('tracking', 'in', ['none', False])], 'required': [('tracking', '!=', 'none')]}" groups="stock.group_production_lot"/>
|
||||
<field name="tracking" invisible="1"/>
|
||||
<field name="package_id" groups="stock.group_tracking_lot"/>
|
||||
<field name="owner_id" groups="stock.group_tracking_owner"/>
|
||||
<field name="location_id" options="{'no_create': True}" groups="stock.group_stock_multi_locations"/>
|
||||
<field name="scrap_location_id" options="{'no_create': True}" groups="stock.group_stock_multi_locations"/>
|
||||
<field name="origin"/>
|
||||
<field name="date_expected"/>
|
||||
<field name="date_expected" attrs="{'readonly': [('state', '=', 'done')]}"/>
|
||||
<field name="picking_id" attrs="{'invisible': [('picking_id', '=', False)]}"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
</group>
|
||||
</sheet>
|
||||
@@ -121,6 +122,7 @@
|
||||
<field name="location_id" options="{'no_create': True}" groups="stock.group_stock_multi_locations"/>
|
||||
<field name="scrap_location_id" options="{'no_create': True}" groups="stock.group_stock_multi_locations"/>
|
||||
<field name="state"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
@@ -162,6 +164,7 @@
|
||||
<field name="lot_id" attrs="{'invisible': [('tracking', '=', 'none')], 'required': [('tracking', '!=', 'none')]}" groups="stock.group_production_lot"/>
|
||||
<field name="package_id" groups="stock.group_tracking_lot"/>
|
||||
<field name="owner_id" groups="stock.group_tracking_owner"/>
|
||||
<field name="company_id" invisible="1"/>
|
||||
<field name="location_id" groups="stock.group_stock_multi_locations" options="{'no_open': True, 'no_create': True}"/>
|
||||
<field name="scrap_location_id" groups="stock.group_stock_multi_locations" options="{'no_open': True, 'no_create': True}" />
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user