Skip to content

Commit

Permalink
[IMP] fieldservice_stock: black, isort, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphael authored and Raphael committed Oct 6, 2020
1 parent 13138e4 commit 79eda98
Show file tree
Hide file tree
Showing 30 changed files with 497 additions and 405 deletions.
61 changes: 28 additions & 33 deletions fieldservice_stock/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",],
}
6 changes: 2 additions & 4 deletions fieldservice_stock/data/fsm_stock_data.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<!-- stock.location -->
<record id="stock_location_field" model="stock.location">
<field name="name">Field</field>
<field name="usage">view</field>
<field name="company_id"></field>
<field name="company_id" />
</record>

</odoo>
6 changes: 4 additions & 2 deletions fieldservice_stock/migrations/12.0.2.0.0/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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';
""")
"""
)
27 changes: 13 additions & 14 deletions fieldservice_stock/models/fsm_equipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
17 changes: 9 additions & 8 deletions fieldservice_stock/models/fsm_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
146 changes: 84 additions & 62 deletions fieldservice_stock/models/fsm_order.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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
Expand All @@ -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
Loading

0 comments on commit 79eda98

Please sign in to comment.