[FIX] stock_dropshipping: create missing dropship picking type

In the function `create_missing_dropship_picking_type()`, the way to
search companies that already have dropship picking type was not robust
enough as it used the translatable `name` field in a search domain and
the ORM `search` method used the translated value of `Dropship` name value
instead of the raw value.
A better approach is to search `stock.picking.type` with a default source
location usage set to `supplier` and a default destination location usage
set to `customer`.

Related to upgrade request: #54154

closes odoo/odoo#59142

X-original-commit: 203bb4d9c113f5c24ad00d39e2ae46b4689117f4
Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
This commit is contained in:
Rémy Baranx (bar)
2020-10-05 15:50:32 +00:00
parent d532a052b2
commit 7a05887cd0
@@ -60,7 +60,14 @@ class ResCompany(models.Model):
@api.model
def create_missing_dropship_picking_type(self):
company_ids = self.env['res.company'].search([])
company_has_dropship_picking_type = self.env['stock.picking.type'].search([('name', '=', 'Dropship')]).mapped('company_id')
company_has_dropship_picking_type = (
self.env['stock.picking.type']
.search([
('default_location_src_id.usage', '=', 'supplier'),
('default_location_dest_id.usage', '=', 'customer'),
])
.mapped('company_id')
)
company_todo_picking_type = company_ids - company_has_dropship_picking_type
company_todo_picking_type._create_dropship_picking_type()