Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] core: assure check_company and _check_company_auto makes sense #162128

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions addons/hr_timesheet/models/project_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ class Project(models.Model):
"Timesheets", compute='_compute_allow_timesheets', store=True, readonly=False,
default=True)
analytic_account_id = fields.Many2one(
# note: replaces ['|', ('company_id', '=', False), ('company_id', '=', company_id)]
domain="""[
'|', ('company_id', '=', False), ('company_id', '=?', company_id),
('partner_id', '=?', partner_id),
]"""
domain="[('partner_id', '=?', partner_id)]",
)
analytic_account_active = fields.Boolean("Active Account", related="analytic_account_id.active", export_string_translation=False)

Expand Down
6 changes: 1 addition & 5 deletions addons/mrp/models/mrp_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,13 @@ def _get_default_is_locked(self):
bom_id = fields.Many2one(
'mrp.bom', 'Bill of Material', readonly=False,
domain="""[
'&',
'|',
('company_id', '=', False),
('company_id', '=', company_id),
'&',
'|',
('product_id','=',product_id),
'&',
('product_tmpl_id.product_variant_ids','=',product_id),
('product_id','=',False),
('type', '=', 'normal')]""",
('type', '=', 'normal')]""",
check_company=True, compute='_compute_bom_id', store=True, precompute=True,
help="Bills of Materials, also called recipes, are used to autocomplete components and work order instructions.")

Expand Down
5 changes: 1 addition & 4 deletions addons/mrp/models/mrp_unbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ class MrpUnbuild(models.Model):
'&',
('product_tmpl_id.product_variant_ids', '=', product_id),
('product_id','=',False),
('type', '=', 'normal'),
'|',
('company_id', '=', company_id),
('company_id', '=', False)
('type', '=', 'normal'),
]""",
compute='_compute_bom_id', store=True,
check_company=True)
Expand Down
3 changes: 1 addition & 2 deletions addons/mrp/models/mrp_workcenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class MrpWorkcenter(models.Model):
'mrp_workcenter_alternative_rel',
'workcenter_id',
'alternative_workcenter_id',
domain="[('id', '!=', id), '|', ('company_id', '=', company_id), ('company_id', '=', False)]",
domain="[('id', '!=', id)]",
string="Alternative Workcenters", check_company=True,
help="Alternative workcenters that can be substituted to this one in order to dispatch production"
)
Expand Down Expand Up @@ -497,7 +497,6 @@ def _close(self):
class MrpWorkCenterCapacity(models.Model):
_name = 'mrp.workcenter.capacity'
_description = 'Work Center Capacity'
_check_company_auto = True

def _default_time_start(self):
workcenter_id = self.workcenter_id.id or self.env.context.get('default_workcenter_id')
Expand Down
2 changes: 1 addition & 1 deletion addons/mrp/models/mrp_workorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _read_group_workcenter_id(self, workcenters, domain):
help="Inventory moves for which you must scan a lot number at this work order")
finished_lot_id = fields.Many2one(
'stock.lot', string='Lot/Serial Number', related='production_id.lot_producing_id',
domain="[('product_id', '=', product_id), ('company_id', '=', company_id)]",
domain="[('product_id', '=', product_id)]",
readonly=False, check_company=True)
time_ids = fields.One2many(
'mrp.workcenter.productivity', 'workorder_id', copy=False)
Expand Down
2 changes: 1 addition & 1 deletion addons/mrp/models/stock_orderpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class StockWarehouseOrderpoint(models.Model):
show_bom = fields.Boolean('Show BoM column', compute='_compute_show_bom')
bom_id = fields.Many2one(
'mrp.bom', string='Bill of Materials', check_company=True,
domain="[('type', '=', 'normal'), '&', '|', ('company_id', '=', company_id), ('company_id', '=', False), '|', ('product_id', '=', product_id), '&', ('product_id', '=', False), ('product_tmpl_id', '=', product_tmpl_id)]")
domain="[('type', '=', 'normal'), '|', ('product_id', '=', product_id), '&', ('product_id', '=', False), ('product_tmpl_id', '=', product_tmpl_id)]")
manufacturing_visibility_days = fields.Float(default=0.0, help="Visibility Days applied on the manufacturing routes.")

def _get_replenishment_order_notification(self):
Expand Down
2 changes: 1 addition & 1 deletion addons/mrp/models/stock_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class StockWarehouse(models.Model):
'stock.rule', 'Stock After Manufacturing Rule', copy=False)
manu_type_id = fields.Many2one(
'stock.picking.type', 'Manufacturing Operation Type',
domain="[('code', '=', 'mrp_operation'), ('company_id', '=', company_id)]", check_company=True)
domain="[('code', '=', 'mrp_operation')]", check_company=True)

pbm_type_id = fields.Many2one('stock.picking.type', 'Picking Before Manufacturing Operation Type', check_company=True)
sam_type_id = fields.Many2one('stock.picking.type', 'Stock After Manufacturing Operation Type', check_company=True)
Expand Down
2 changes: 1 addition & 1 deletion addons/project/models/project_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _set_favorite_user_ids(self, is_favorite):
company_id = fields.Many2one('res.company', string='Company', compute="_compute_company_id", inverse="_inverse_company_id", store=True, readonly=False)
currency_id = fields.Many2one('res.currency', compute="_compute_currency_id", string="Currency", readonly=True)
analytic_account_id = fields.Many2one('account.analytic.account', string="Analytic Account", copy=False, ondelete='set null',
domain="['|', ('company_id', '=', False), ('company_id', '=?', company_id)]", check_company=True,
check_company=True,
help="Analytic account to which this project, its tasks and its timesheets are linked. \n"
"Track the costs and revenues of your project by setting this analytic account on your related documents (e.g. sales orders, invoices, purchase orders, vendor bills, expenses etc.).\n"
"This analytic account can be changed on each task individually if necessary.\n"
Expand Down
6 changes: 3 additions & 3 deletions addons/repair/models/repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _default_picking_type_id(self):
copy=False, readonly=True, tracking=True, check_company=True)
product_id = fields.Many2one(
'product.product', string='Product to Repair',
domain="[('type', 'in', ['product', 'consu']), '|', ('company_id', '=', company_id), ('company_id', '=', False), '|', ('id', 'in', picking_product_ids), ('id', '=?', picking_product_id)]",
domain="[('type', 'in', ['product', 'consu']), '|', ('id', 'in', picking_product_ids), ('id', '=?', picking_product_id)]",
check_company=True)
product_qty = fields.Float(
'Product Quantity',
Expand All @@ -85,7 +85,7 @@ def _default_picking_type_id(self):
'stock.lot', 'Lot/Serial',
default=False,
compute="compute_lot_id", store=True,
domain="[('product_id','=', product_id), '|', ('company_id', '=', False), ('company_id', '=', company_id)]", check_company=True,
domain="[('product_id','=', product_id)]", check_company=True,
help="Products repaired are all belonging to this lot")
tracking = fields.Selection(string='Product Tracking', related="product_id.tracking", readonly=False)

Expand All @@ -94,7 +94,7 @@ def _default_picking_type_id(self):
'stock.picking.type', 'Operation Type', copy=True, readonly=False,
compute='_compute_picking_type_id', store=True,
default=_default_picking_type_id,
domain="[('code', '=', 'repair_operation'), ('company_id', '=', company_id)]",
domain="[('code', '=', 'repair_operation')]",
required=True, precompute=True, check_company=True, index=True)
procurement_group_id = fields.Many2one(
'procurement.group', 'Procurement Group',
Expand Down
2 changes: 1 addition & 1 deletion addons/resource/models/resource_calendar_leaves.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def default_get(self, fields_list):
company_id = fields.Many2one(
'res.company', string="Company", readonly=True, store=True,
default=lambda self: self.env.company, compute='_compute_company_id')
calendar_id = fields.Many2one('resource.calendar', 'Working Hours', domain="[('company_id', 'in', [company_id, False])]", check_company=True, index=True)
calendar_id = fields.Many2one('resource.calendar', 'Working Hours', check_company=True, index=True)
date_from = fields.Datetime('Start Date', required=True)
date_to = fields.Datetime('End Date', compute="_compute_date_to", readonly=False, required=True, store=True)
resource_id = fields.Many2one(
Expand Down
7 changes: 3 additions & 4 deletions addons/sale/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,13 @@ def _rec_names_search(self):
string="Payment Terms",
compute='_compute_payment_term_id',
store=True, readonly=False, precompute=True, check_company=True, # Unrequired company
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]")
)
pricelist_id = fields.Many2one(
comodel_name='product.pricelist',
string="Pricelist",
compute='_compute_pricelist_id',
store=True, readonly=False, precompute=True, check_company=True, # Unrequired company
tracking=1,
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
help="If you change the pricelist, only newly added lines will be affected.")
currency_id = fields.Many2one(
comodel_name='res.currency',
Expand Down Expand Up @@ -201,7 +200,7 @@ def _rec_names_search(self):
store=True, readonly=False, precompute=True, ondelete="set null",
change_default=True, check_company=True, # Unrequired company
tracking=True,
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]")
)

# Lines and line based computes
order_line = fields.One2many(
Expand Down Expand Up @@ -253,7 +252,7 @@ def _rec_names_search(self):
comodel_name='account.analytic.account',
string="Analytic Account",
copy=False, check_company=True, # Unrequired company
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]")
)
tag_ids = fields.Many2many(
comodel_name='crm.tag',
relation='sale_order_tag_rel', column1='order_id', column2='tag_id',
Expand Down
2 changes: 1 addition & 1 deletion addons/sale_crm/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SaleOrder(models.Model):

opportunity_id = fields.Many2one(
'crm.lead', string='Opportunity', check_company=True,
domain="[('type', '=', 'opportunity'), '|', ('company_id', '=', False), ('company_id', '=', company_id)]")
domain="[('type', '=', 'opportunity')]")

def action_confirm(self):
return super(SaleOrder, self.with_context({k:v for k,v in self._context.items() if k != 'default_tag_ids'})).action_confirm()
1 change: 0 additions & 1 deletion addons/sale_management/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ class ResCompany(models.Model):

sale_order_template_id = fields.Many2one(
"sale.order.template", string="Default Sale Template",
domain="['|', ('company_id', '=', False), ('company_id', '=', id)]",
check_company=True,
)
2 changes: 1 addition & 1 deletion addons/sale_management/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SaleOrder(models.Model):
string="Quotation Template",
compute='_compute_sale_order_template_id',
store=True, readonly=False, check_company=True, precompute=True,
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]")
)
sale_order_option_ids = fields.One2many(
comodel_name='sale.order.option', inverse_name='order_id',
string="Optional Products Lines",
Expand Down
2 changes: 1 addition & 1 deletion addons/sales_team/models/crm_team_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CrmTeamMember(models.Model):
crm_team_id = fields.Many2one(
'crm.team', string='Sales Team',
group_expand='_read_group_expand_full', # Always display all the teams
default=False, # TDE: temporary fix to activate depending computed fields
default=False, # TDE: temporary fix to activate depending on computed fields
check_company=True, index=True, ondelete="cascade", required=True)
user_id = fields.Many2one(
'res.users', string='Salesperson', # TDE FIXME check responsible field
Expand Down
4 changes: 2 additions & 2 deletions addons/stock/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,11 +666,11 @@ class ProductTemplate(models.Model):
], ondelete={'product': 'set consu'})
property_stock_production = fields.Many2one(
'stock.location', "Production Location",
company_dependent=True, check_company=True, domain="[('usage', '=', 'production'), '|', ('company_id', '=', False), ('company_id', '=', allowed_company_ids[0])]",
company_dependent=True, check_company=True, domain="[('usage', '=', 'production')]",
help="This stock location will be used, instead of the default one, as the source location for stock moves generated by manufacturing orders.")
property_stock_inventory = fields.Many2one(
'stock.location', "Inventory Location",
company_dependent=True, check_company=True, domain="[('usage', '=', 'inventory'), '|', ('company_id', '=', False), ('company_id', '=', allowed_company_ids[0])]",
company_dependent=True, check_company=True, domain="[('usage', '=', 'inventory')]",
help="This stock location will be used, instead of the default one, as the source location for stock moves generated when you do an inventory.")
sale_delay = fields.Integer(
'Customer Lead Time', default=0,
Expand Down
2 changes: 0 additions & 2 deletions addons/stock/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ class Partner(models.Model):

property_stock_customer = fields.Many2one(
'stock.location', string="Customer Location", company_dependent=True, check_company=True,
domain="['|', ('company_id', '=', False), ('company_id', '=', allowed_company_ids[0])]",
help="The stock location used as destination when sending goods to this contact.")
property_stock_supplier = fields.Many2one(
'stock.location', string="Vendor Location", company_dependent=True, check_company=True,
domain="['|', ('company_id', '=', False), ('company_id', '=', allowed_company_ids[0])]",
help="The stock location used as source when receiving goods from this contact.")
picking_warn = fields.Selection(WARNING_MESSAGE, 'Stock Picking', help=WARNING_HELP, default='no-message')
picking_warn_msg = fields.Text('Message for Stock Picking')
4 changes: 2 additions & 2 deletions addons/stock/models/stock_package_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class StockPackageLevel(models.Model):

package_id = fields.Many2one(
'stock.quant.package', 'Package', required=True, check_company=True,
domain="[('location_id', 'child_of', parent.location_id), '|', ('company_id', '=', False), ('company_id', '=', company_id)]")
domain="[('location_id', 'child_of', parent.location_id)]")
picking_id = fields.Many2one('stock.picking', 'Picking', check_company=True)
move_ids = fields.One2many('stock.move', 'package_level_id')
move_line_ids = fields.One2many('stock.move.line', 'package_level_id')
location_id = fields.Many2one('stock.location', 'From', compute='_compute_location_id', check_company=True)
location_dest_id = fields.Many2one(
'stock.location', 'To', check_company=True,
compute="_compute_location_dest_id", store=True, readonly=False, precompute=True,
domain="[('id', 'child_of', parent.location_dest_id), '|', ('company_id', '=', False), ('company_id', '=', company_id)]")
domain="[('id', 'child_of', parent.location_dest_id)]")
is_done = fields.Boolean('Done', compute='_compute_is_done', inverse='_set_is_done')
state = fields.Selection([
('draft', 'Draft'),
Expand Down
6 changes: 3 additions & 3 deletions addons/stock/models/stock_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ def _default_name(self):
partner_id = fields.Many2one('res.partner', 'Address', default=lambda self: self.env.company.partner_id, check_company=True)
view_location_id = fields.Many2one(
'stock.location', 'View Location',
domain="[('usage', '=', 'view'), ('company_id', '=', company_id)]",
domain="[('usage', '=', 'view')]",
required=True, check_company=True)
lot_stock_id = fields.Many2one(
'stock.location', 'Location Stock',
domain="[('usage', '=', 'internal'), ('company_id', '=', company_id)]",
domain="[('usage', '=', 'internal')]",
required=True, check_company=True)
code = fields.Char('Short Name', required=True, size=5, help="Short name used to identify your warehouse")
route_ids = fields.Many2many(
'stock.route', 'stock_route_warehouse', 'warehouse_id', 'route_id',
'Routes',
domain="[('warehouse_selectable', '=', True), '|', ('company_id', '=', False), ('company_id', '=', company_id)]",
domain="[('warehouse_selectable', '=', True)]",
help='Defaults routes through the warehouse', check_company=True, copy=False)
reception_steps = fields.Selection([
('one_step', 'Receive goods directly (1 step)'),
Expand Down
7 changes: 7 additions & 0 deletions odoo/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2950,6 +2950,13 @@ def setup_nonrelated(self, model):
_logger.warning("Field %s with unknown comodel_name %r", self, self.comodel_name)
self.comodel_name = '_unknown'

def setup(self, model):
super().setup(model)
if self.check_company and 'company_id' not in model._fields and model._name != 'res.company' and self.comodel_name != 'res.users' and not self.company_dependent:
MiquelRForgeFlow marked this conversation as resolved.
Show resolved Hide resolved
_logger.warning("%s: check_company attribute will be ignored because the model doesn't have company_id field", self)
elif self.check_company and 'company_id' in model._fields and model._name != 'res.company' and self.comodel_name != 'res.users' and isinstance(self.domain, str) and 'company_id' in self.domain:
_logger.warning("%s: company_id in domain deprecated, already has check_company attribute", self)

def get_domain_list(self, model):
""" Return a list domain from the domain parameter. """
domain = self.domain
Expand Down
5 changes: 4 additions & 1 deletion odoo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ class BaseModel(metaclass=MetaModel):
_fold_name = 'fold' #: field to determine folded groups in kanban views

_translate = True # False disables translations export for this model (Old API)
_check_company_auto = False
_check_company_auto = None
"""On write and create, call ``_check_company`` to ensure companies
consistency on the relational fields having ``check_company=True``
as attribute.
Expand Down Expand Up @@ -3476,6 +3476,9 @@ def _setup_complete(self):
# register constraints and onchange methods
cls._init_constraints_onchanges()

if cls._check_company_auto is not None and 'company_id' not in cls._fields and self._name != 'res.company':
MiquelRForgeFlow marked this conversation as resolved.
Show resolved Hide resolved
_logger.warning("%s._check_company_auto attribute will be ignored because it doesn't have a company_id field", self._name)

@api.model
def fields_get(self, allfields=None, attributes=None):
""" fields_get([allfields][, attributes])
Expand Down