still working on is_property
This commit is contained in:
parent
63c8a75c98
commit
263164fc0e
2 changed files with 52 additions and 47 deletions
|
|
@ -29,7 +29,8 @@ class ResPartner(models.Model):
|
||||||
is_property = fields.Boolean(
|
is_property = fields.Boolean(
|
||||||
string='Is Property',
|
string='Is Property',
|
||||||
default=False,
|
default=False,
|
||||||
compute='_compute_is_property'
|
compute='_compute_is_property',
|
||||||
|
store=True
|
||||||
) # True if property, False if not
|
) # True if property, False if not
|
||||||
|
|
||||||
interest_level = fields.Selection(
|
interest_level = fields.Selection(
|
||||||
|
|
@ -54,10 +55,24 @@ class ResPartner(models.Model):
|
||||||
string="Property ids"
|
string="Property ids"
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.depends('relation_owner_ids')
|
@api.onchange('category_id')
|
||||||
|
@api.depends('category_id')
|
||||||
def _compute_is_property(self):
|
def _compute_is_property(self):
|
||||||
for partner in self:
|
property_tag = self.env.ref('bemade_sethy_configuration.partner_tag_property', raise_if_not_found=False)
|
||||||
partner.is_property = partner.category_id.name == 'Property'
|
for record in self:
|
||||||
|
# Check if the property tag exists. If it doesn't, set is_property to False.
|
||||||
|
# Because module installation order is not guaranteed, the tag may not exist yet when this method is called.
|
||||||
|
# This is due to store=True on the is_property field.
|
||||||
|
if property_tag is None:
|
||||||
|
record.is_property = False
|
||||||
|
else:
|
||||||
|
record.is_property = record.category_id & property_tag
|
||||||
|
|
||||||
|
@api.depends('relation_property_ids')
|
||||||
|
def _compute_property_count(self):
|
||||||
|
for record in self:
|
||||||
|
record.property_count = len(record.relation_property_ids)
|
||||||
|
record.is_owner = record.property_count > 0
|
||||||
|
|
||||||
@api.depends('relation_all_ids')
|
@api.depends('relation_all_ids')
|
||||||
def _compute_owner_ids(self):
|
def _compute_owner_ids(self):
|
||||||
|
|
@ -66,7 +81,6 @@ class ResPartner(models.Model):
|
||||||
lambda line: (
|
lambda line: (
|
||||||
line.type_id.name == 'Owner' and not line.is_inverse)
|
line.type_id.name == 'Owner' and not line.is_inverse)
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.depends('relation_all_ids')
|
@api.depends('relation_all_ids')
|
||||||
def _compute_property_ids(self):
|
def _compute_property_ids(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
|
|
@ -74,53 +88,45 @@ class ResPartner(models.Model):
|
||||||
lambda line: (
|
lambda line: (
|
||||||
line.type_id.name == 'Owner' and line.is_inverse)
|
line.type_id.name == 'Owner' and line.is_inverse)
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.onchange('is_property')
|
|
||||||
def _onchange_is_property(self):
|
|
||||||
""" Set is_company to True when is_property is set to True. """
|
|
||||||
if self.is_property:
|
|
||||||
self.is_company = True
|
|
||||||
|
|
||||||
@api.onchange('is_company')
|
|
||||||
def _onchange_is_company(self):
|
|
||||||
""" Set is_property to False when is_company is set to False. """
|
|
||||||
if not self.is_company:
|
|
||||||
self.is_property = False
|
|
||||||
|
|
||||||
@api.onchange('lot_number')
|
@api.onchange('lot_number')
|
||||||
def _onchange_lot_number(self):
|
def _onchange_lot_number(self):
|
||||||
for lot in self:
|
for lot in self:
|
||||||
if lot.lot_number:
|
if lot.lot_number:
|
||||||
lot.name = "Lot " + str(lot.lot_number)
|
lot.name = "Lot " + str(lot.lot_number)
|
||||||
|
|
||||||
@api.depends('relation_property_ids')
|
# @api.model_create_multi
|
||||||
def _compute_property_count(self):
|
# def create(self, vals_list):
|
||||||
for record in self:
|
# # Get the property tag reference outside the loop to avoid repeated searches.
|
||||||
record.property_count = len(record.relation_property_ids)
|
# property_tag = self.env.ref('bemade_sethy_configuration.partner_tag_property', raise_if_not_found=False)
|
||||||
record.is_owner = record.property_count > 0
|
# # Iterate over each set of values in the list.
|
||||||
|
# for vals in vals_list:
|
||||||
|
# # Check if 'is_property' is in the values of the current record.
|
||||||
|
# if 'is_property' in vals:
|
||||||
|
# if vals['is_property'] and property_tag:
|
||||||
|
# # Add the tag to category_id if is_property is True.
|
||||||
|
# vals['category_id'] = [(4, property_tag.id)]
|
||||||
|
# elif not vals['is_property'] and property_tag:
|
||||||
|
# # Remove the tag from category_id if is_property is False.
|
||||||
|
# vals['category_id'] = [(3, property_tag.id)]
|
||||||
|
# # Call super and pass the modified vals_list.
|
||||||
|
# return super(ResPartner, self).create(vals_list)
|
||||||
|
#
|
||||||
|
# @api.onchange('is_property')
|
||||||
|
# def _inverse_is_property(self):
|
||||||
|
# property_tag = self.env.ref('bemade_sethy_configuration.partner_tag_property', raise_if_not_found=False)
|
||||||
|
# for partner in self:
|
||||||
|
# if partner.is_property:
|
||||||
|
# partner.category_id |= property_tag
|
||||||
|
# else:
|
||||||
|
# partner.category_id -= property_tag
|
||||||
|
|
||||||
@api.model_create_multi
|
@api.model_create_multi
|
||||||
def create(self, vals_list):
|
def create(self, vals_list):
|
||||||
# Get the property tag reference outside the loop to avoid repeated searches.
|
# if 'state_id' not in values or 'country_id' not in values, then set it from the current user's company
|
||||||
property_tag = self.env.ref('bemade_sethy_configuration.partner_tag_property', raise_if_not_found=False)
|
|
||||||
# Iterate over each set of values in the list.
|
|
||||||
for vals in vals_list:
|
for vals in vals_list:
|
||||||
# Check if 'is_property' is in the values of the current record.
|
if 'state_id' not in vals or 'country_id' not in vals:
|
||||||
if 'is_property' in vals:
|
user_company = self.env.user.company_id
|
||||||
if vals['is_property'] and property_tag:
|
if 'state_id' not in vals and user_company.state_id:
|
||||||
# Add the tag to category_id if is_property is True.
|
vals['state_id'] = user_company.state_id.id
|
||||||
vals['category_id'] = [(4, property_tag.id)]
|
vals['country_id'] = user_company.country_id.id
|
||||||
elif not vals['is_property'] and property_tag:
|
return super(Partner, self).create(vals)
|
||||||
# Remove the tag from category_id if is_property is False.
|
|
||||||
vals['category_id'] = [(3, property_tag.id)]
|
|
||||||
# Call super and pass the modified vals_list.
|
|
||||||
return super(ResPartner, self).create(vals_list)
|
|
||||||
|
|
||||||
@api.onchange('is_property')
|
|
||||||
def _inverse_is_property(self):
|
|
||||||
property_tag = self.env.ref('bemade_sethy_configuration.partner_tag_property', raise_if_not_found=False)
|
|
||||||
for partner in self:
|
|
||||||
if partner.is_property:
|
|
||||||
partner.category_id |= property_tag
|
|
||||||
else:
|
|
||||||
partner.category_id -= property_tag
|
|
||||||
|
|
@ -7,8 +7,7 @@
|
||||||
<field name="inherit_id" ref="base.view_partner_form"/>
|
<field name="inherit_id" ref="base.view_partner_form"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="company_type" position="after">
|
<field name="company_type" position="after">
|
||||||
<label for="is_property" string="Property"/>
|
<field name="is_property" invisible="True"/>
|
||||||
<field name="is_property"/>
|
|
||||||
</field>
|
</field>
|
||||||
|
|
||||||
<xpath expr="//field[@name='name' and @id='company']" position="replace">
|
<xpath expr="//field[@name='name' and @id='company']" position="replace">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue