Skip to content
Permalink
Browse files

[REF] repair: multi company

task-2081645
  • Loading branch information...
sle-odoo committed Oct 9, 2019
1 parent badd0c0 commit c5f368f0de208b10f7e6f0e334160baa62a5ad7e
Showing with 54 additions and 34 deletions.
  1. +34 −22 addons/repair/models/repair.py
  2. +4 −0 addons/repair/models/stock_traceability.py
  3. +16 −12 addons/repair/views/repair_views.xml
@@ -1,4 +1,3 @@

# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models, _
@@ -9,7 +8,7 @@
class StockMove(models.Model):
_inherit = 'stock.move'

repair_id = fields.Many2one('repair.order')
repair_id = fields.Many2one('repair.order', check_company=True)


class Repair(models.Model):
@@ -32,7 +31,8 @@ def _default_stock_location(self):
states={'confirmed': [('readonly', True)]})
product_id = fields.Many2one(
'product.product', string='Product to Repair',
readonly=True, required=True, states={'draft': [('readonly', False)]})
domain="[('type', 'in', ['product', 'consu']), '|', ('company_id', '=', company_id), ('company_id', '=', False)]",
readonly=True, required=True, states={'draft': [('readonly', False)]}, check_company=True)
product_qty = fields.Float(
'Product Quantity',
default=1.0, digits='Product Unit of Measure',
@@ -43,11 +43,11 @@ def _default_stock_location(self):
product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id')
partner_id = fields.Many2one(
'res.partner', 'Customer',
index=True, states={'confirmed': [('readonly', True)]},
index=True, states={'confirmed': [('readonly', True)]}, check_company=True,
help='Choose partner for whom the order will be invoiced and delivered. You can find a partner by its Name, TIN, Email or Internal Reference.')
address_id = fields.Many2one(
'res.partner', 'Delivery Address',
domain="[('parent_id','=',partner_id)]",
domain="[('parent_id','=',partner_id)]", check_company=True,
states={'confirmed': [('readonly', True)]})
default_address_id = fields.Many2one('res.partner', compute='_compute_default_address_id')
state = fields.Selection([
@@ -69,12 +69,12 @@ def _default_stock_location(self):
location_id = fields.Many2one(
'stock.location', 'Location',
default=_default_stock_location,
index=True, readonly=True, required=True,
index=True, readonly=True, required=True, check_company=True,
help="This is the location where the product to repair is located.",
states={'draft': [('readonly', False)], 'confirmed': [('readonly', True)]})
lot_id = fields.Many2one(
'stock.production.lot', 'Lot/Serial',
domain="[('product_id','=', product_id)]",
domain="[('product_id','=', product_id), ('company_id', '=', company_id)]", check_company=True,
help="Products repaired are all belonging to this lot")
guarantee_limit = fields.Date('Warranty Expiration', states={'confirmed': [('readonly', True)]})
operations = fields.One2many(
@@ -83,8 +83,8 @@ def _default_stock_location(self):
pricelist_id = fields.Many2one(
'product.pricelist', 'Pricelist',
default=lambda self: self.env['product.pricelist'].search([], limit=1).id,
help='Pricelist of the selected partner.')
partner_invoice_id = fields.Many2one('res.partner', 'Invoicing Address')
help='Pricelist of the selected partner.', check_company=True)
partner_invoice_id = fields.Many2one('res.partner', 'Invoicing Address', check_company=True)
invoice_method = fields.Selection([
("none", "No Invoice"),
("b4repair", "Before Repair"),
@@ -98,16 +98,17 @@ def _default_stock_location(self):
domain=[('type', '=', 'out_invoice')])
move_id = fields.Many2one(
'stock.move', 'Move',
copy=False, readonly=True, tracking=True,
copy=False, readonly=True, tracking=True, check_company=True,
help="Move created by the repair order")
fees_lines = fields.One2many(
'repair.fee', 'repair_id', 'Operations',
copy=True, readonly=True, states={'draft': [('readonly', False)]})
internal_notes = fields.Text('Internal Notes')
quotation_notes = fields.Text('Quotation Notes')
user_id = fields.Many2one('res.users', string="Responsible", default=lambda self: self.env.user)
user_id = fields.Many2one('res.users', string="Responsible", default=lambda self: self.env.user, check_company=True)
company_id = fields.Many2one(
'res.company', 'Company',
readonly=True, required=True, index=True,
default=lambda self: self.env.company)
tag_ids = fields.Many2many('repair.tags', string="Tags")
invoiced = fields.Boolean('Invoiced', copy=False, readonly=True)
@@ -543,16 +544,20 @@ class RepairLine(models.Model):
name = fields.Text('Description', required=True)
repair_id = fields.Many2one(
'repair.order', 'Repair Order Reference',
index=True, ondelete='cascade')
index=True, ondelete='cascade', check_company=True)
company_id = fields.Many2one('res.company', related='repair_id.company_id')
type = fields.Selection([
('add', 'Add'),
('remove', 'Remove')], 'Type', required=True)
product_id = fields.Many2one('product.product', 'Product', required=True)
product_id = fields.Many2one(
'product.product', 'Product', required=True, check_company=True,
domain="[('type', 'in', ['product', 'consu']), '|', ('company_id', '=', company_id), ('company_id', '=', False)]")
invoiced = fields.Boolean('Invoiced', copy=False, readonly=True)
price_unit = fields.Float('Unit Price', required=True, digits='Product Price')
price_subtotal = fields.Float('Subtotal', compute='_compute_price_subtotal', store=True, digits=0)
tax_id = fields.Many2many(
'account.tax', 'repair_operation_line_tax', 'repair_operation_line_id', 'tax_id', 'Taxes')
'account.tax', 'repair_operation_line_tax', 'repair_operation_line_id', 'tax_id', 'Taxes',
domain="[('type_tax_use','=','sale'), ('company_id', '=', company_id)]", check_company=True)
product_uom_qty = fields.Float(
'Quantity', default=1.0,
digits='Product Unit of Measure', required=True)
@@ -562,17 +567,19 @@ class RepairLine(models.Model):
product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id')
invoice_line_id = fields.Many2one(
'account.move.line', 'Invoice Line',
copy=False, readonly=True)
copy=False, readonly=True, check_company=True)
location_id = fields.Many2one(
'stock.location', 'Source Location',
index=True, required=True)
location_dest_id = fields.Many2one(
'stock.location', 'Dest. Location',
index=True, required=True)
index=True, required=True, check_company=True)
move_id = fields.Many2one(
'stock.move', 'Inventory Move',
copy=False, readonly=True)
lot_id = fields.Many2one('stock.production.lot', 'Lot/Serial')
lot_id = fields.Many2one(
'stock.production.lot', 'Lot/Serial',
domain="[('product_id','=', product_id), ('company_id', '=', company_id)]", check_company=True)
state = fields.Selection([
('draft', 'Draft'),
('confirmed', 'Confirmed'),
@@ -608,12 +615,12 @@ def onchange_operation_type(self):
args = self.repair_id.company_id and [('company_id', '=', self.repair_id.company_id.id)] or []
warehouse = self.env['stock.warehouse'].search(args, limit=1)
self.location_id = warehouse.lot_stock_id
self.location_dest_id = self.env['stock.location'].search([('usage', '=', 'production')], limit=1).id
self.location_dest_id = self.env['stock.location'].search([('usage', '=', 'production'), ('company_id', '=', self.repair_id.company_id.id)], limit=1)
else:
self.price_unit = 0.0
self.tax_id = False
self.location_id = self.env['stock.location'].search([('usage', '=', 'production')], limit=1).id
self.location_dest_id = self.env['stock.location'].search([('scrap_location', '=', True)], limit=1).id
self.location_dest_id = self.env['stock.location'].search([('scrap_location', '=', True), ('company_id', 'in', [self.repair_id.company_id.id, False])], limit=1).id

@api.onchange('repair_id', 'product_id', 'product_uom_qty')
def onchange_product_id(self):
@@ -667,15 +674,20 @@ class RepairFee(models.Model):
repair_id = fields.Many2one(
'repair.order', 'Repair Order Reference',
index=True, ondelete='cascade', required=True)
company_id = fields.Many2one('res.company', related='repair_id.company_id')
name = fields.Text('Description', index=True, required=True)
product_id = fields.Many2one('product.product', 'Product')
product_id = fields.Many2one(
'product.product', 'Product', check_company=True,
domain="[('type', 'in', ['product', 'consu']), '|', ('company_id', '=', company_id), ('company_id', '=', False)]")
product_uom_qty = fields.Float('Quantity', digits='Product Unit of Measure', required=True, default=1.0)
price_unit = fields.Float('Unit Price', required=True)
product_uom = fields.Many2one('uom.uom', 'Product Unit of Measure', required=True, domain="[('category_id', '=', product_uom_category_id)]")
product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id')
price_subtotal = fields.Float('Subtotal', compute='_compute_price_subtotal', store=True, digits=0)
tax_id = fields.Many2many('account.tax', 'repair_fee_line_tax', 'repair_fee_line_id', 'tax_id', 'Taxes')
invoice_line_id = fields.Many2one('account.move.line', 'Invoice Line', copy=False, readonly=True)
tax_id = fields.Many2many(
'account.tax', 'repair_fee_line_tax', 'repair_fee_line_id', 'tax_id', 'Taxes',
domain="[('type_tax_use','=','sale'), ('company_id', '=', company_id)]", check_company=True)
invoice_line_id = fields.Many2one('account.move.line', 'Invoice Line', copy=False, readonly=True, check_company=True)
invoiced = fields.Boolean('Invoiced', copy=False, readonly=True)

@api.depends('price_unit', 'repair_id', 'product_uom_qty', 'product_id')
@@ -1,5 +1,8 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models, api


class MrpStockReport(models.TransientModel):
_inherit = 'stock.traceability.report'

@@ -20,3 +23,4 @@ def _get_linked_move_lines(self, move_line):
if not is_used:
is_used = move_line.move_id.repair_id and move_line.produce_line_ids
return move_lines, is_used

@@ -63,14 +63,14 @@
<group>
<group>
<field name="tracking" invisible="1" attrs="{'readonly': 1}"/>
<field name="product_id" domain="[('type', 'in', ['product', 'consu'])]"/>
<field name="product_id" />
<field name="product_uom_category_id" invisible="1"/>
<label for="product_qty"/>
<div class="o_row">
<field name="product_qty"/>
<field name="product_uom" groups="uom.group_uom"/>
</div>
<field name="lot_id" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}" groups="stock.group_production_lot" attrs="{'required':[('tracking', 'in', ['serial', 'lot'])], 'invisible': [('tracking', 'not in', ['serial', 'lot'])], 'readonly': [('state', '=', 'done')]}"/>
<field name="lot_id" context="{'default_product_id': product_id}" groups="stock.group_production_lot" attrs="{'required':[('tracking', 'in', ['serial', 'lot'])], 'invisible': [('tracking', 'not in', ['serial', 'lot'])], 'readonly': [('state', '=', 'done')]}"/>
<field name="partner_id" widget="res_partner_many2one" attrs="{'required':[('invoice_method','!=','none')]}" context="{'show_vat': True}"/>
<field name="address_id" groups="sale.group_delivery_invoice_address"/>
<field name="user_id"/>
@@ -91,6 +91,7 @@
<form string="Operations">
<group>
<group>
<field name="company_id" invisible="1"/>
<field name="type"/>
<field name="product_id"/>
<field name="name"/>
@@ -101,12 +102,12 @@
<field name="product_uom" groups="uom.group_uom"/>
</div>
<field name="price_unit"/>
<field name="tax_id" widget="many2many_tags" domain="[('type_tax_use','=','sale')]"/>
<field name="tax_id" widget="many2many_tags"/>
<field name="invoiced" invisible="1"/>
<field name="price_subtotal" widget="monetary" invisible="1"/>
</group>
<group>
<field name="lot_id" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}" groups="stock.group_production_lot"/>
<field name="lot_id" context="{'default_product_id': product_id}" groups="stock.group_production_lot"/>
<field name="location_id" options="{'no_create': True}" groups="stock.group_stock_multi_locations"/>
<field name="location_dest_id" options="{'no_create': True}" groups="stock.group_stock_multi_locations"/>
</group>
@@ -117,17 +118,18 @@
</group>
</form>
<tree string="Operations" editable="bottom">
<field name="company_id" invisible="1"/>
<field name="type"/>
<field name="product_id" domain="[('type', '!=', 'service')]"/>
<field name="product_id"/>
<field name='name' optional="show"/>
<field name="product_uom_category_id" invisible="1"/>
<field name="lot_id" domain="[('product_id', '=', product_id)]" context="{'default_product_id': product_id}" groups="stock.group_production_lot"/>
<field name="lot_id" context="{'default_product_id': product_id}" groups="stock.group_production_lot"/>
<field name="location_id" options="{'no_create': True}" groups="stock.group_stock_multi_locations" optional="show"/>
<field name="location_dest_id" options="{'no_create': True}" groups="stock.group_stock_multi_locations" optional="show"/>
<field name="product_uom_qty" string="Quantity"/>
<field name="product_uom" string="UoM" groups="uom.group_uom" optional="show"/>
<field name="price_unit"/>
<field name="tax_id" widget="many2many_tags" domain="[('type_tax_use','=','sale')]" optional="show"/>
<field name="tax_id" widget="many2many_tags" optional="show"/>
<field name="price_subtotal" widget="monetary"/>
</tree>
</field>
@@ -144,11 +146,11 @@
<div class="oe_clear"/>
</page>
<page string="Operations">
<!-- <field name="invoice_id"/> -->
<field name="fees_lines">
<form string="Fees">
<group>
<field name="product_id" domain="[('type','=','service')]" required="True"/>
<field name="company_id" invisible="1"/>
<field name="product_id" required="True"/>
<field name="name"/>
<field name="product_uom_category_id" invisible="1"/>
<label for="product_uom_qty"/>
@@ -157,18 +159,19 @@
<field name="product_uom" groups="uom.group_uom"/>
</div>
<field name="price_unit"/>
<field widget="many2many_tags" name="tax_id" domain="[('type_tax_use','=','sale')]"/>
<field widget="many2many_tags" name="tax_id"/>
<field name="price_subtotal" widget="monetary" invisible="1"/>
</group>
</form>
<tree string="Fees" editable="bottom">
<field name="product_id" domain="[('type','=','service')]" required="True"/>
<field name="company_id" invisible="1"/>
<field name="product_id" required="True"/>
<field name='name' optional="show"/>
<field name="product_uom_qty" string="Quantity"/>
<field name="product_uom_category_id" invisible="1"/>
<field name="product_uom" string="Unit of Measure" groups="uom.group_uom" optional="show"/>
<field name="price_unit"/>
<field name="tax_id" domain="[('type_tax_use', '=', 'sale')]" widget="many2many_tags" optional="show"/>
<field name="tax_id" widget="many2many_tags" optional="show"/>
<field name="price_subtotal" widget="monetary"/>
</tree>
</field>
@@ -205,6 +208,7 @@
<field name="model">repair.order</field>
<field name="arch" type="xml">
<kanban class="o_kanban_mobile">
<field name="company_id" invisible="1"/>
<field name="name" />
<field name="product_id" />
<field name="partner_id"/>

0 comments on commit c5f368f

Please sign in to comment.
You can’t perform that action at this time.