From 79eda98feaaed3548aee31be2fd4300bef5cc2f1 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 5 Oct 2020 17:41:44 -0700 Subject: [PATCH] [IMP] fieldservice_stock: black, isort, prettier --- fieldservice_stock/__manifest__.py | 61 +++--- fieldservice_stock/data/fsm_stock_data.xml | 6 +- .../migrations/12.0.2.0.0/post-migration.py | 6 +- fieldservice_stock/models/fsm_equipment.py | 27 ++- fieldservice_stock/models/fsm_location.py | 17 +- fieldservice_stock/models/fsm_order.py | 146 +++++++++------ fieldservice_stock/models/fsm_territory.py | 4 +- fieldservice_stock/models/fsm_wizard.py | 4 +- .../models/procurement_group.py | 4 +- fieldservice_stock/models/product_template.py | 4 +- fieldservice_stock/models/stock_move.py | 30 +-- fieldservice_stock/models/stock_move_line.py | 9 +- fieldservice_stock/models/stock_picking.py | 11 +- .../models/stock_picking_type.py | 4 +- .../models/stock_production_lot.py | 7 +- fieldservice_stock/models/stock_request.py | 127 +++++++------ .../models/stock_request_order.py | 33 ++-- fieldservice_stock/models/stock_rule.py | 28 ++- fieldservice_stock/views/fsm_equipment.xml | 26 ++- fieldservice_stock/views/fsm_location.xml | 13 +- fieldservice_stock/views/fsm_order.xml | 177 +++++++++++------- fieldservice_stock/views/fsm_territory.xml | 19 +- fieldservice_stock/views/product_template.xml | 13 +- fieldservice_stock/views/stock.xml | 40 ++-- .../views/stock_picking_type.xml | 10 +- .../views/stock_production_lot.xml | 19 +- fieldservice_stock/views/stock_request.xml | 13 +- .../views/stock_request_order.xml | 37 ++-- .../odoo/addons/fieldservice_stock | 1 + setup/fieldservice_stock/setup.py | 6 + 30 files changed, 497 insertions(+), 405 deletions(-) create mode 120000 setup/fieldservice_stock/odoo/addons/fieldservice_stock create mode 100644 setup/fieldservice_stock/setup.py diff --git a/fieldservice_stock/__manifest__.py b/fieldservice_stock/__manifest__.py index e98b166362..df0a3a0527 100644 --- a/fieldservice_stock/__manifest__.py +++ b/fieldservice_stock/__manifest__.py @@ -2,39 +2,34 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Field Service - Stock', - 'summary': 'Integrate the logistics operations with Field Service', - 'version': '12.0.2.2.0', - 'category': 'Field Service', - 'author': "Open Source Integrators, " - "Brian McMaster, " - "Odoo Community Association (OCA)", - 'website': 'https://github.com/OCA/field-service', - 'depends': [ - 'fieldservice', - 'stock_request_direction', - 'stock_request_picking_type', + "name": "Field Service - Stock", + "summary": "Integrate the logistics operations with Field Service", + "version": "12.0.2.2.0", + "category": "Field Service", + "author": "Open Source Integrators, " + "Brian McMaster, " + "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/field-service", + "depends": [ + "fieldservice", + "stock_request_direction", + "stock_request_picking_type", ], - 'data': [ - 'security/ir.model.access.csv', - 'data/fsm_stock_data.xml', - 'views/fsm_territory.xml', - 'views/fsm_location.xml', - 'views/fsm_order.xml', - 'views/stock.xml', - 'views/fsm_equipment.xml', - 'views/product_template.xml', - 'views/stock_picking_type.xml', - 'views/stock_production_lot.xml', - 'views/stock_request.xml', - 'views/stock_request_order.xml', - ], - 'license': 'AGPL-3', - 'development_status': 'Beta', - 'maintainers': [ - 'brian10048', - 'wolfhall', - 'max3903', - 'smangukiya', + "data": [ + "security/ir.model.access.csv", + "data/fsm_stock_data.xml", + "views/fsm_territory.xml", + "views/fsm_location.xml", + "views/fsm_order.xml", + "views/stock.xml", + "views/fsm_equipment.xml", + "views/product_template.xml", + "views/stock_picking_type.xml", + "views/stock_production_lot.xml", + "views/stock_request.xml", + "views/stock_request_order.xml", ], + "license": "AGPL-3", + "development_status": "Beta", + "maintainers": ["brian10048", "wolfhall", "max3903", "smangukiya",], } diff --git a/fieldservice_stock/data/fsm_stock_data.xml b/fieldservice_stock/data/fsm_stock_data.xml index 290cd237e7..2a8f54c2d9 100644 --- a/fieldservice_stock/data/fsm_stock_data.xml +++ b/fieldservice_stock/data/fsm_stock_data.xml @@ -1,11 +1,9 @@ - + - Field view - + - diff --git a/fieldservice_stock/migrations/12.0.2.0.0/post-migration.py b/fieldservice_stock/migrations/12.0.2.0.0/post-migration.py index 2855328b90..c3221ab722 100644 --- a/fieldservice_stock/migrations/12.0.2.0.0/post-migration.py +++ b/fieldservice_stock/migrations/12.0.2.0.0/post-migration.py @@ -6,8 +6,10 @@ def migrate(env, version): if not version: return - env.execute(""" + env.execute( + """ UPDATE stock_picking_type SET create_fsm_equipment = 'true' WHERE code = 'outgoing'; - """) + """ + ) diff --git a/fieldservice_stock/models/fsm_equipment.py b/fieldservice_stock/models/fsm_equipment.py index b395666caf..d7b51014d2 100644 --- a/fieldservice_stock/models/fsm_equipment.py +++ b/fieldservice_stock/models/fsm_equipment.py @@ -5,32 +5,31 @@ class FSMEquipment(models.Model): - _inherit = 'fsm.equipment' + _inherit = "fsm.equipment" - product_id = fields.Many2one( - 'product.product', string='Product', required=True) - lot_id = fields.Many2one( - 'stock.production.lot', string='Serial #', required=True) + product_id = fields.Many2one("product.product", string="Product", required=True) + lot_id = fields.Many2one("stock.production.lot", string="Serial #", required=True) current_stock_location_id = fields.Many2one( - 'stock.location', string='Current Inventory Location', - compute='_compute_current_stock_loc_id') + "stock.location", + string="Current Inventory Location", + compute="_compute_current_stock_loc_id", + ) @api.multi def _compute_current_stock_loc_id(self): for equipment in self: - quants = self.env['stock.quant'].search( - [('lot_id', '=', equipment.lot_id.id)], order="id desc", - limit=1) + quants = self.env["stock.quant"].search( + [("lot_id", "=", equipment.lot_id.id)], order="id desc", limit=1 + ) if quants and quants.location_id: - equipment.current_stock_location_id = \ - quants.location_id.id + equipment.current_stock_location_id = quants.location_id.id else: equipment.current_stock_location_id = False @api.model def create(self, vals): res = super(FSMEquipment, self).create(vals) - if 'lot_id' in vals: + if "lot_id" in vals: res.lot_id.fsm_equipment_id = res.id return res @@ -39,7 +38,7 @@ def write(self, vals): for equipment in self: prev_lot = equipment.lot_id res = super(FSMEquipment, equipment).write(vals) - if 'lot_id' in vals: + if "lot_id" in vals: prev_lot.fsm_equipment_id = False equipment.lot_id.fsm_equipment_id = equipment.id return res diff --git a/fieldservice_stock/models/fsm_location.py b/fieldservice_stock/models/fsm_location.py index d5b35bcd8b..e4d8f0298c 100644 --- a/fieldservice_stock/models/fsm_location.py +++ b/fieldservice_stock/models/fsm_location.py @@ -5,16 +5,17 @@ class FSMLocation(models.Model): - _inherit = 'fsm.location' + _inherit = "fsm.location" inventory_location_id = fields.Many2one( - 'stock.location', string='Inventory Location', required=True, - default=lambda self: self.env.ref('stock.stock_location_customers')) - shipping_address_id = fields.Many2one('res.partner', - string='Shipping Location') + "stock.location", + string="Inventory Location", + required=True, + default=lambda self: self.env.ref("stock.stock_location_customers"), + ) + shipping_address_id = fields.Many2one("res.partner", string="Shipping Location") - @api.onchange('fsm_parent_id') + @api.onchange("fsm_parent_id") def _onchange_fsm_parent_id(self): super(FSMLocation, self)._onchange_fsm_parent_id() - self.inventory_location_id = \ - self.fsm_parent_id.inventory_location_id.id + self.inventory_location_id = self.fsm_parent_id.inventory_location_id.id diff --git a/fieldservice_stock/models/fsm_order.py b/fieldservice_stock/models/fsm_order.py index 1c470ad338..f36401c8a1 100644 --- a/fieldservice_stock/models/fsm_order.py +++ b/fieldservice_stock/models/fsm_order.py @@ -1,106 +1,124 @@ # Copyright (C) 2018 - TODAY, Brian McMaster # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models, _ - +from odoo import _, api, fields, models from odoo.exceptions import UserError - REQUEST_STATES = [ - ('draft', 'Draft'), - ('submitted', 'Submitted'), - ('open', 'In progress'), - ('done', 'Done'), - ('cancel', 'Cancelled')] + ("draft", "Draft"), + ("submitted", "Submitted"), + ("open", "In progress"), + ("done", "Done"), + ("cancel", "Cancelled"), +] class FSMOrder(models.Model): - _inherit = 'fsm.order' + _inherit = "fsm.order" @api.model def _default_warehouse_id(self): company = self.env.user.company_id.id - warehouse_ids = self.env['stock.warehouse'].search( - [('company_id', '=', company)], limit=1) + warehouse_ids = self.env["stock.warehouse"].search( + [("company_id", "=", company)], limit=1 + ) return warehouse_ids and warehouse_ids.id @api.model def _get_move_domain(self): - return [('picking_id.picking_type_id.code', 'in', - ('outgoing', 'incoming'))] + return [("picking_id.picking_type_id.code", "in", ("outgoing", "incoming"))] - stock_request_ids = fields.One2many('stock.request', 'fsm_order_id', - string="Order Lines") + stock_request_ids = fields.One2many( + "stock.request", "fsm_order_id", string="Order Lines" + ) - picking_ids = fields.One2many('stock.picking', 'fsm_order_id', - string='Transfers') - delivery_count = fields.Integer(string='Delivery Orders', - compute='_compute_picking_ids') + picking_ids = fields.One2many("stock.picking", "fsm_order_id", string="Transfers") + delivery_count = fields.Integer( + string="Delivery Orders", compute="_compute_picking_ids" + ) procurement_group_id = fields.Many2one( - 'procurement.group', 'Procurement Group', copy=False) + "procurement.group", "Procurement Group", copy=False + ) inventory_location_id = fields.Many2one( - related='location_id.inventory_location_id', readonly=True) - warehouse_id = fields.Many2one('stock.warehouse', string='Warehouse', - required=True, - default=_default_warehouse_id, - help="Warehouse used to ship the materials") - return_count = fields.Integer(string='Return Orders', - compute='_compute_picking_ids') - request_stage = fields.Selection(REQUEST_STATES, string='Request State', - default='draft', readonly=True, - store=True) + related="location_id.inventory_location_id", readonly=True + ) + warehouse_id = fields.Many2one( + "stock.warehouse", + string="Warehouse", + required=True, + default=_default_warehouse_id, + help="Warehouse used to ship the materials", + ) + return_count = fields.Integer( + string="Return Orders", compute="_compute_picking_ids" + ) + request_stage = fields.Selection( + REQUEST_STATES, + string="Request State", + default="draft", + readonly=True, + store=True, + ) move_ids = fields.One2many( - 'stock.move', 'fsm_order_id', string='Operations', - domain=_get_move_domain) + "stock.move", "fsm_order_id", string="Operations", domain=_get_move_domain + ) @api.multi def action_request_submit(self): for rec in self: if not rec.stock_request_ids: - raise UserError(_('Please create a stock request.')) + raise UserError(_("Please create a stock request.")) for line in rec.stock_request_ids: - if line.state == 'draft': + if line.state == "draft": if line.order_id: line.order_id.action_submit() else: line.action_submit() - rec.request_stage = 'submitted' + rec.request_stage = "submitted" @api.multi def action_request_cancel(self): for rec in self: if not rec.stock_request_ids: - raise UserError(_('Please create a stock request.')) + raise UserError(_("Please create a stock request.")) for line in rec.stock_request_ids: - if line.state in ('draft', 'submitted'): + if line.state in ("draft", "submitted"): if line.order_id: line.order_id.action_cancel() else: line.action_cancel() - rec.request_stage = 'cancel' + rec.request_stage = "cancel" @api.multi def action_request_draft(self): for rec in self: if not rec.stock_request_ids: - raise UserError(_('Please create a stock request.')) + raise UserError(_("Please create a stock request.")) for line in rec.stock_request_ids: - if line.state == 'cancel': + if line.state == "cancel": if line.order_id: line.order_id.action_draft() else: line.action_draft() - rec.request_stage = 'draft' + rec.request_stage = "draft" - @api.depends('picking_ids') + @api.depends("picking_ids") def _compute_picking_ids(self): for order in self: order.delivery_count = len( - [picking for picking in order.picking_ids if - picking.picking_type_id.code == 'outgoing']) + [ + picking + for picking in order.picking_ids + if picking.picking_type_id.code == "outgoing" + ] + ) order.return_count = len( - [picking for picking in order.picking_ids if - picking.picking_type_id.code == 'incoming']) + [ + picking + for picking in order.picking_ids + if picking.picking_type_id.code == "incoming" + ] + ) @api.multi def action_view_delivery(self): @@ -109,16 +127,18 @@ def action_view_delivery(self): of given fsm order ids. It can either be a in a list or in a form view, if there is only one delivery order to show. """ - action = self.env.ref('stock.action_picking_tree_all').read()[0] - pickings = self.mapped('picking_ids') - delivery_ids = [picking.id for picking in pickings if - picking.picking_type_id.code == 'outgoing'] + action = self.env.ref("stock.action_picking_tree_all").read()[0] + pickings = self.mapped("picking_ids") + delivery_ids = [ + picking.id + for picking in pickings + if picking.picking_type_id.code == "outgoing" + ] if len(delivery_ids) > 1: - action['domain'] = [('id', 'in', delivery_ids)] + action["domain"] = [("id", "in", delivery_ids)] elif pickings: - action['views'] = [(self.env.ref('stock.view_picking_form').id, - 'form')] - action['res_id'] = delivery_ids[0] + action["views"] = [(self.env.ref("stock.view_picking_form").id, "form")] + action["res_id"] = delivery_ids[0] return action @api.multi @@ -128,14 +148,16 @@ def action_view_returns(self): of given fsm order ids. It can either be a in a list or in a form view, if there is only one return order to show. """ - action = self.env.ref('stock.action_picking_tree_all').read()[0] - pickings = self.mapped('picking_ids') - return_ids = [picking.id for picking in pickings if - picking.picking_type_id.code == 'incoming'] + action = self.env.ref("stock.action_picking_tree_all").read()[0] + pickings = self.mapped("picking_ids") + return_ids = [ + picking.id + for picking in pickings + if picking.picking_type_id.code == "incoming" + ] if len(return_ids) > 1: - action['domain'] = [('id', 'in', return_ids)] + action["domain"] = [("id", "in", return_ids)] elif pickings: - action['views'] = [(self.env.ref('stock.view_picking_form').id, - 'form')] - action['res_id'] = return_ids[0] + action["views"] = [(self.env.ref("stock.view_picking_form").id, "form")] + action["res_id"] = return_ids[0] return action diff --git a/fieldservice_stock/models/fsm_territory.py b/fieldservice_stock/models/fsm_territory.py index 12959591af..bdff957024 100644 --- a/fieldservice_stock/models/fsm_territory.py +++ b/fieldservice_stock/models/fsm_territory.py @@ -4,6 +4,6 @@ class FSMTerritory(models.Model): - _inherit = 'fsm.territory' + _inherit = "fsm.territory" - warehouse_id = fields.Many2one('stock.warehouse', string='Warehouse') + warehouse_id = fields.Many2one("stock.warehouse", string="Warehouse") diff --git a/fieldservice_stock/models/fsm_wizard.py b/fieldservice_stock/models/fsm_wizard.py index 7b5be78958..96a1266b3e 100644 --- a/fieldservice_stock/models/fsm_wizard.py +++ b/fieldservice_stock/models/fsm_wizard.py @@ -5,9 +5,9 @@ class FSMWizard(models.TransientModel): - _inherit = 'fsm.wizard' + _inherit = "fsm.wizard" def _prepare_fsm_location(self, partner): res = super()._prepare_fsm_location(partner) - res['inventory_location_id'] = partner.property_stock_customer.id + res["inventory_location_id"] = partner.property_stock_customer.id return res diff --git a/fieldservice_stock/models/procurement_group.py b/fieldservice_stock/models/procurement_group.py index 39e60cda88..1c02672451 100644 --- a/fieldservice_stock/models/procurement_group.py +++ b/fieldservice_stock/models/procurement_group.py @@ -4,6 +4,6 @@ class ProcurementGroup(models.Model): - _inherit = 'procurement.group' + _inherit = "procurement.group" - fsm_order_id = fields.Many2one('fsm.order', 'Field Service Order') + fsm_order_id = fields.Many2one("fsm.order", "Field Service Order") diff --git a/fieldservice_stock/models/product_template.py b/fieldservice_stock/models/product_template.py index 54195f55d7..d0bb3485db 100644 --- a/fieldservice_stock/models/product_template.py +++ b/fieldservice_stock/models/product_template.py @@ -5,6 +5,6 @@ class ProductTemplate(models.Model): - _inherit = 'product.template' + _inherit = "product.template" - create_fsm_equipment = fields.Boolean(string='Creates a FSM Equipment') + create_fsm_equipment = fields.Boolean(string="Creates a FSM Equipment") diff --git a/fieldservice_stock/models/stock_move.py b/fieldservice_stock/models/stock_move.py index 92bbb8da84..22fb6cecd1 100644 --- a/fieldservice_stock/models/stock_move.py +++ b/fieldservice_stock/models/stock_move.py @@ -6,27 +6,27 @@ class StockMove(models.Model): _inherit = "stock.move" - fsm_order_id = fields.Many2one('fsm.order', string='Field Service Order') + fsm_order_id = fields.Many2one("fsm.order", string="Field Service Order") def prepare_equipment_values(self, move_line): - return {'name': '%s (%s)' % ( - move_line.product_id.name, move_line.lot_id.name), - 'product_id': move_line.product_id.id, - 'lot_id': move_line.lot_id.id, - 'location_id': - move_line.move_id.stock_request_ids.fsm_order_id.location_id.id, - 'current_location_id': - move_line.move_id.stock_request_ids.fsm_order_id.location_id.id, - 'current_stock_location_id': move_line.location_dest_id.id} + return { + "name": "{} ({})".format(move_line.product_id.name, move_line.lot_id.name), + "product_id": move_line.product_id.id, + "lot_id": move_line.lot_id.id, + "location_id": move_line.move_id.stock_request_ids.fsm_order_id.location_id.id, + "current_location_id": move_line.move_id.stock_request_ids.fsm_order_id.location_id.id, + "current_stock_location_id": move_line.location_dest_id.id, + } def _action_done(self): res = super()._action_done() for rec in self: - if (rec.state == 'done' - and rec.picking_type_id.create_fsm_equipment - and rec.product_tmpl_id.create_fsm_equipment): + if ( + rec.state == "done" + and rec.picking_type_id.create_fsm_equipment + and rec.product_tmpl_id.create_fsm_equipment + ): for line in rec.move_line_ids: vals = self.prepare_equipment_values(line) - line.lot_id.fsm_equipment_id = \ - rec.env['fsm.equipment'].create(vals) + line.lot_id.fsm_equipment_id = rec.env["fsm.equipment"].create(vals) return res diff --git a/fieldservice_stock/models/stock_move_line.py b/fieldservice_stock/models/stock_move_line.py index 92c6dbba1a..07be351cce 100644 --- a/fieldservice_stock/models/stock_move_line.py +++ b/fieldservice_stock/models/stock_move_line.py @@ -17,8 +17,9 @@ def _action_done(self): move_id = None if move_id: for request in rec.move_id.allocation_ids: - if (request.stock_request_id.state == 'done' - and request.stock_request_id.fsm_order_id): - request.stock_request_id.\ - fsm_order_id.request_stage = 'done' + if ( + request.stock_request_id.state == "done" + and request.stock_request_id.fsm_order_id + ): + request.stock_request_id.fsm_order_id.request_stage = "done" return res diff --git a/fieldservice_stock/models/stock_picking.py b/fieldservice_stock/models/stock_picking.py index 06abdeb450..20f94d4247 100644 --- a/fieldservice_stock/models/stock_picking.py +++ b/fieldservice_stock/models/stock_picking.py @@ -4,14 +4,15 @@ class StockPicking(models.Model): - _inherit = 'stock.picking' + _inherit = "stock.picking" - fsm_order_id = fields.Many2one(related="group_id.fsm_order_id", - string="Field Service Order", store=True) + fsm_order_id = fields.Many2one( + related="group_id.fsm_order_id", string="Field Service Order", store=True + ) @api.model def create(self, vals): res = super().create(vals) - if vals.get('fsm_order_id'): - res.fsm_order_id = vals.get('fsm_order_id') + if vals.get("fsm_order_id"): + res.fsm_order_id = vals.get("fsm_order_id") return res diff --git a/fieldservice_stock/models/stock_picking_type.py b/fieldservice_stock/models/stock_picking_type.py index 5fe0671881..f4001b609e 100644 --- a/fieldservice_stock/models/stock_picking_type.py +++ b/fieldservice_stock/models/stock_picking_type.py @@ -4,10 +4,10 @@ class StockPickingType(models.Model): - _inherit = 'stock.picking.type' + _inherit = "stock.picking.type" create_fsm_equipment = fields.Boolean( name="Create FSM Equipment", help="Products with the 'Creates a FSM Equipment' flag " - "will automatically be converted to an FSM Equipment." + "will automatically be converted to an FSM Equipment.", ) diff --git a/fieldservice_stock/models/stock_production_lot.py b/fieldservice_stock/models/stock_production_lot.py index 5e52651e3e..c8430c080e 100644 --- a/fieldservice_stock/models/stock_production_lot.py +++ b/fieldservice_stock/models/stock_production_lot.py @@ -5,7 +5,8 @@ class StockProductionLot(models.Model): - _inherit = 'stock.production.lot' + _inherit = "stock.production.lot" - fsm_equipment_id = fields.Many2one('fsm.equipment', - string='Equipment', readonly=True) + fsm_equipment_id = fields.Many2one( + "fsm.equipment", string="Equipment", readonly=True + ) diff --git a/fieldservice_stock/models/stock_request.py b/fieldservice_stock/models/stock_request.py index 3acf4440e5..b62d9f63b1 100644 --- a/fieldservice_stock/models/stock_request.py +++ b/fieldservice_stock/models/stock_request.py @@ -1,97 +1,109 @@ # Copyright (C) 2019 Open Source Integrators # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models, _ +from odoo import _, api, fields, models from odoo.exceptions import UserError class StockRequest(models.Model): - _inherit = 'stock.request' + _inherit = "stock.request" fsm_order_id = fields.Many2one( - 'fsm.order', string="FSM Order", ondelete='cascade', - index=True, copy=False) + "fsm.order", string="FSM Order", ondelete="cascade", index=True, copy=False + ) - @api.onchange('direction', 'fsm_order_id') + @api.onchange("direction", "fsm_order_id") def _onchange_location_id(self): super()._onchange_location_id() if self.fsm_order_id: - if self.direction == 'outbound': + if self.direction == "outbound": # Inventory location of the FSM location of the order - self.location_id = \ + self.location_id = ( self.fsm_order_id.location_id.inventory_location_id.id + ) else: # Otherwise the stock location of the warehouse - self.location_id = \ - self.fsm_order_id.warehouse_id.lot_stock_id.id + self.location_id = self.fsm_order_id.warehouse_id.lot_stock_id.id def prepare_order_values(self, vals): res = { - 'expected_date': vals['expected_date'], - 'picking_policy': vals['picking_policy'], - 'warehouse_id': vals['warehouse_id'], - 'direction': vals['direction'], - 'location_id': vals['location_id'], + "expected_date": vals["expected_date"], + "picking_policy": vals["picking_policy"], + "warehouse_id": vals["warehouse_id"], + "direction": vals["direction"], + "location_id": vals["location_id"], } - if 'fsm_order_id' in vals and vals['fsm_order_id']: - res.update({'fsm_order_id': vals['fsm_order_id']}) + if "fsm_order_id" in vals and vals["fsm_order_id"]: + res.update({"fsm_order_id": vals["fsm_order_id"]}) return res @api.model def create(self, vals): - if 'fsm_order_id' in vals and vals['fsm_order_id']: - fsm_order = self.env['fsm.order'].browse(vals['fsm_order_id']) - fsm_order.request_stage = 'draft' - vals['warehouse_id'] = fsm_order.warehouse_id.id - picking_type_id = self.env['stock.picking.type'].search( - [('code', '=', 'stock_request_order'), - ('warehouse_id', '=', vals['warehouse_id'])], - limit=1) - order = self.env['stock.request.order'].search([ - ('fsm_order_id', '=', vals['fsm_order_id']), - ('warehouse_id', '=', vals['warehouse_id']), - ('picking_type_id', '=', picking_type_id.id), - ('direction', '=', vals['direction']), - ('state', '=', 'draft')], order="id asc") + if "fsm_order_id" in vals and vals["fsm_order_id"]: + fsm_order = self.env["fsm.order"].browse(vals["fsm_order_id"]) + fsm_order.request_stage = "draft" + vals["warehouse_id"] = fsm_order.warehouse_id.id + picking_type_id = self.env["stock.picking.type"].search( + [ + ("code", "=", "stock_request_order"), + ("warehouse_id", "=", vals["warehouse_id"]), + ], + limit=1, + ) + order = self.env["stock.request.order"].search( + [ + ("fsm_order_id", "=", vals["fsm_order_id"]), + ("warehouse_id", "=", vals["warehouse_id"]), + ("picking_type_id", "=", picking_type_id.id), + ("direction", "=", vals["direction"]), + ("state", "=", "draft"), + ], + order="id asc", + ) # User created a new SRO Manually if len(order) > 1: - raise UserError(_('There is already a Stock Request Order \ + raise UserError( + _( + "There is already a Stock Request Order \ with the same Field Service Order and \ Warehouse that is in Draft state. Please \ add this Stock Request there. \ - (%s)') % order[0].name) + (%s)" + ) + % order[0].name + ) # Made from an FSO for the first time, create the SRO here - elif not order and vals.get('fsm_order_id'): + elif not order and vals.get("fsm_order_id"): values = self.prepare_order_values(vals) - values.update({ - 'picking_type_id': picking_type_id.id, - 'warehouse_id': vals['warehouse_id'], - }) - vals['order_id'] = self.env['stock.request.order'].\ - create(values).id + values.update( + { + "picking_type_id": picking_type_id.id, + "warehouse_id": vals["warehouse_id"], + } + ) + vals["order_id"] = self.env["stock.request.order"].create(values).id # There is an SRO made from FSO, assign here - elif len(order) == 1 and vals.get('fsm_order_id'): - vals['expected_date'] = order.expected_date - vals['order_id'] = order.id + elif len(order) == 1 and vals.get("fsm_order_id"): + vals["expected_date"] = order.expected_date + vals["order_id"] = order.id return super().create(vals) def _prepare_procurement_values(self, group_id=False): res = super()._prepare_procurement_values(group_id=group_id) if self.fsm_order_id: - res.update({ - 'fsm_order_id': self.fsm_order_id.id, - 'partner_id': - self.fsm_order_id.location_id.shipping_address_id.id or - self.fsm_order_id.location_id.partner_id.id - }) + res.update( + { + "fsm_order_id": self.fsm_order_id.id, + "partner_id": self.fsm_order_id.location_id.shipping_address_id.id + or self.fsm_order_id.location_id.partner_id.id, + } + ) return res def _prepare_procurement_group_values(self): if self.fsm_order_id: - order = self.env['fsm.order'].browse(self.fsm_order_id.id) - return {'name': order.name, - 'fsm_order_id': order.id, - 'move_type': 'direct'} + order = self.env["fsm.order"].browse(self.fsm_order_id.id) + return {"name": order.name, "fsm_order_id": order.id, "move_type": "direct"} else: return {} @@ -99,17 +111,18 @@ def _prepare_procurement_group_values(self): def _action_confirm(self): for req in self: if (not req.procurement_group_id) and req.fsm_order_id: - fsm_order = self.env['fsm.order'].browse(req.fsm_order_id.id) - group = self.env['procurement.group'].search([ - ('fsm_order_id', '=', fsm_order.id)]) + fsm_order = self.env["fsm.order"].browse(req.fsm_order_id.id) + group = self.env["procurement.group"].search( + [("fsm_order_id", "=", fsm_order.id)] + ) if not group: values = req._prepare_procurement_group_values() - group = req.env['procurement.group'].create(values) + group = req.env["procurement.group"].create(values) if req.order_id: req.order_id.procurement_group_id = group.id req.procurement_group_id = group.id res = super(StockRequest, req)._action_confirm() - fsm_order.request_stage = 'open' + fsm_order.request_stage = "open" else: res = super(StockRequest, req)._action_confirm() return res diff --git a/fieldservice_stock/models/stock_request_order.py b/fieldservice_stock/models/stock_request_order.py index e96d3687c4..5d662d287a 100644 --- a/fieldservice_stock/models/stock_request_order.py +++ b/fieldservice_stock/models/stock_request_order.py @@ -5,50 +5,49 @@ class StockRequestOrder(models.Model): - _inherit = 'stock.request.order' + _inherit = "stock.request.order" fsm_order_id = fields.Many2one( - 'fsm.order', string="FSM Order", ondelete='cascade', - index=True, copy=False) + "fsm.order", string="FSM Order", ondelete="cascade", index=True, copy=False + ) - @api.onchange('warehouse_id', 'direction', 'fsm_order_id') + @api.onchange("warehouse_id", "direction", "fsm_order_id") def _onchange_location_id(self): super()._onchange_location_id() if self.fsm_order_id: - if self.direction == 'outbound': + if self.direction == "outbound": # Inventory location of the FSM location of the order - self.location_id = \ + self.location_id = ( self.fsm_order_id.location_id.inventory_location_id.id + ) else: # Otherwise the stock location of the warehouse - self.location_id = \ - self.fsm_order_id.warehouse_id.lot_stock_id.id + self.location_id = self.fsm_order_id.warehouse_id.lot_stock_id.id self.change_childs() def change_childs(self): super().change_childs() - if not self._context.get('no_change_childs', False): + if not self._context.get("no_change_childs", False): for line in self.stock_request_ids: line.fsm_order_id = self.fsm_order_id.id def _prepare_procurement_group_values(self): if self.fsm_order_id: - order = self.env['fsm.order'].browse(self.fsm_order_id.id) - return {'name': order.name, - 'fsm_order_id': order.id, - 'move_type': 'direct'} + order = self.env["fsm.order"].browse(self.fsm_order_id.id) + return {"name": order.name, "fsm_order_id": order.id, "move_type": "direct"} else: return {} @api.multi def action_confirm(self): if self.fsm_order_id: - fsm_order = self.env['fsm.order'].browse(self.fsm_order_id.id) - group = self.env['procurement.group'].search([ - ('fsm_order_id', '=', fsm_order.id)]) + fsm_order = self.env["fsm.order"].browse(self.fsm_order_id.id) + group = self.env["procurement.group"].search( + [("fsm_order_id", "=", fsm_order.id)] + ) if not group: values = self._prepare_procurement_group_values() - group = self.env['procurement.group'].create(values) + group = self.env["procurement.group"].create(values) self.procurement_group_id = group[0].id self.change_childs() return super().action_confirm() diff --git a/fieldservice_stock/models/stock_rule.py b/fieldservice_stock/models/stock_rule.py index 63c0ec3dff..84dde2f114 100644 --- a/fieldservice_stock/models/stock_rule.py +++ b/fieldservice_stock/models/stock_rule.py @@ -4,12 +4,28 @@ class StockRule(models.Model): - _inherit = 'stock.rule' + _inherit = "stock.rule" - def _get_stock_move_values(self, product_id, product_qty, product_uom, - location_id, name, origin, values, group_id): + def _get_stock_move_values( + self, + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + values, + group_id, + ): vals = super()._get_stock_move_values( - product_id, product_qty, product_uom, location_id, name, origin, - values, group_id) - vals.update({'fsm_order_id': values.get('fsm_order_id')}) + product_id, + product_qty, + product_uom, + location_id, + name, + origin, + values, + group_id, + ) + vals.update({"fsm_order_id": values.get("fsm_order_id")}) return vals diff --git a/fieldservice_stock/views/fsm_equipment.xml b/fieldservice_stock/views/fsm_equipment.xml index 1ce8ae287f..9ccffd7e4a 100644 --- a/fieldservice_stock/views/fsm_equipment.xml +++ b/fieldservice_stock/views/fsm_equipment.xml @@ -1,32 +1,30 @@ - + - fsm.equipment.form.stock fsm.equipment - + - - - - + + + + - fsm.equipment.model fsm.equipment - + - + diff --git a/fieldservice_stock/views/fsm_location.xml b/fieldservice_stock/views/fsm_location.xml index 2de8f469b9..11a5350655 100644 --- a/fieldservice_stock/views/fsm_location.xml +++ b/fieldservice_stock/views/fsm_location.xml @@ -1,21 +1,20 @@ - - fsm.location - + - + - + - diff --git a/fieldservice_stock/views/fsm_order.xml b/fieldservice_stock/views/fsm_order.xml index 15af98d18a..b9d26d294f 100644 --- a/fieldservice_stock/views/fsm_order.xml +++ b/fieldservice_stock/views/fsm_order.xml @@ -1,96 +1,137 @@ - fsm.order.form.stock fsm.order - +
- - -
-
- + - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + +
-
diff --git a/fieldservice_stock/views/fsm_territory.xml b/fieldservice_stock/views/fsm_territory.xml index bc6698c152..810c48c970 100644 --- a/fieldservice_stock/views/fsm_territory.xml +++ b/fieldservice_stock/views/fsm_territory.xml @@ -1,29 +1,30 @@ - fsm.territory.warehouse.tree fsm.territory - + - + - fsm.territory.warehouse.form fsm.territory - + - + - diff --git a/fieldservice_stock/views/product_template.xml b/fieldservice_stock/views/product_template.xml index 6b9d6f36e3..21c4547210 100644 --- a/fieldservice_stock/views/product_template.xml +++ b/fieldservice_stock/views/product_template.xml @@ -1,16 +1,15 @@ - + - product.template - + - + - diff --git a/fieldservice_stock/views/stock.xml b/fieldservice_stock/views/stock.xml index edabe5eb06..ed22bfe833 100644 --- a/fieldservice_stock/views/stock.xml +++ b/fieldservice_stock/views/stock.xml @@ -1,22 +1,24 @@ - - - - - - - + + + diff --git a/fieldservice_stock/views/stock_picking_type.xml b/fieldservice_stock/views/stock_picking_type.xml index d197e10f6a..277811a2f1 100644 --- a/fieldservice_stock/views/stock_picking_type.xml +++ b/fieldservice_stock/views/stock_picking_type.xml @@ -1,16 +1,12 @@ - + - stock.picking.type - + - - + - - diff --git a/fieldservice_stock/views/stock_production_lot.xml b/fieldservice_stock/views/stock_production_lot.xml index 4f23b37cad..97e92de5b8 100644 --- a/fieldservice_stock/views/stock_production_lot.xml +++ b/fieldservice_stock/views/stock_production_lot.xml @@ -1,24 +1,23 @@ - + - stock.production.lot - + - + - + - - + {'search_default_group_by_product': 1, 'default_product_id': context.get('product_id', False)} - diff --git a/fieldservice_stock/views/stock_request.xml b/fieldservice_stock/views/stock_request.xml index c7736fbde7..fc8c864ccd 100644 --- a/fieldservice_stock/views/stock_request.xml +++ b/fieldservice_stock/views/stock_request.xml @@ -1,24 +1,21 @@ - + - stock.request - + - + - stock.request - + - + - diff --git a/fieldservice_stock/views/stock_request_order.xml b/fieldservice_stock/views/stock_request_order.xml index b13d8b4b35..91a3bd1912 100644 --- a/fieldservice_stock/views/stock_request_order.xml +++ b/fieldservice_stock/views/stock_request_order.xml @@ -1,14 +1,13 @@ - stock.request.order - + - + - { + { 'default_fsm_order_id': fsm_order_id, 'default_expected_date': expected_date, 'default_picking_policy': picking_policy, @@ -19,35 +18,41 @@ 'default_company_id': company_id, 'default_state': state} - - + + - stock.request.order - + - + - stock.request.order - + - + - + - diff --git a/setup/fieldservice_stock/odoo/addons/fieldservice_stock b/setup/fieldservice_stock/odoo/addons/fieldservice_stock new file mode 120000 index 0000000000..6bb1c1f529 --- /dev/null +++ b/setup/fieldservice_stock/odoo/addons/fieldservice_stock @@ -0,0 +1 @@ +../../../../fieldservice_stock \ No newline at end of file diff --git a/setup/fieldservice_stock/setup.py b/setup/fieldservice_stock/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/fieldservice_stock/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)