[FIX] stock: manual inter-company flow
Usecase: - Create a route without company - Create a push rule for company B from intercompany to stock - Apply the push rule on product and set in on a product. - Connect with a user in company A - Create a move from stock(company A) to intercompany. - Confirm the move -> The receipt for company B is not created. Multiple issues: - The rule is not found because it belong to the other company and is filtered by the record rules. -> Aplly the seach as sudo if the move is going to a location without company. - Record rule error because a move from intercompany to company B is created with a user from company A that has no access to company A. -> Search and read company values and create the move as super user. Based on work from Simon Lejeune <sle@odoo.com> closes odoo/odoo#38124 X-original-commit: a80262e8b97256cac4bc5c406bc74a05f7189a00 Signed-off-by: Simon Goffin (sig) <sig@openerp.com>
This commit is contained in:
@@ -661,8 +661,10 @@ class StockMove(models.Model):
|
||||
domain = [('location_src_id', '=', move.location_dest_id.id), ('action', 'in', ('push', 'pull_push'))]
|
||||
# first priority goes to the preferred routes defined on the move itself (e.g. coming from a SO line)
|
||||
warehouse_id = move.warehouse_id or move.picking_id.picking_type_id.warehouse_id
|
||||
rules = self.env['procurement.group']._search_rule(move.route_ids, move.product_id, warehouse_id, domain)
|
||||
|
||||
if not self.env.context.get('force_company', False) and move.location_dest_id.company_id == self.env.user.company_id:
|
||||
rules = self.env['procurement.group']._search_rule(move.route_ids, move.product_id, warehouse_id, domain)
|
||||
else:
|
||||
rules = self.sudo().env['procurement.group']._search_rule(move.route_ids, move.product_id, warehouse_id, domain)
|
||||
# Make sure it is not returning the return
|
||||
if rules and (not move.origin_returned_move_id or move.origin_returned_move_id.location_dest_id.id != rules.location_id.id):
|
||||
rules._run_push(move)
|
||||
|
||||
@@ -169,18 +169,21 @@ class StockRule(models.Model):
|
||||
move._push_apply()
|
||||
else:
|
||||
new_move_vals = self._push_prepare_move_copy_values(move, new_date)
|
||||
new_move = move.copy(new_move_vals)
|
||||
new_move = move.sudo().copy(new_move_vals)
|
||||
move.write({'move_dest_ids': [(4, new_move.id)]})
|
||||
new_move._action_confirm()
|
||||
|
||||
def _push_prepare_move_copy_values(self, move_to_copy, new_date):
|
||||
company_id = self.company_id.id
|
||||
if not company_id:
|
||||
company_id = self.sudo().warehouse_id and self.sudo().warehouse_id.company_id.id or self.sudo().picking_type_id.warehouse_id.company_id.id
|
||||
new_move_vals = {
|
||||
'origin': move_to_copy.origin or move_to_copy.picking_id.name or "/",
|
||||
'location_id': move_to_copy.location_dest_id.id,
|
||||
'location_dest_id': self.location_id.id,
|
||||
'date': new_date,
|
||||
'date_expected': new_date,
|
||||
'company_id': self.company_id.id,
|
||||
'company_id': company_id,
|
||||
'picking_id': False,
|
||||
'picking_type_id': self.picking_type_id.id,
|
||||
'propagate_cancel': self.propagate_cancel,
|
||||
|
||||
Reference in New Issue
Block a user