more function
This commit is contained in:
parent
263164fc0e
commit
cc8677c8f9
11 changed files with 173 additions and 78 deletions
|
|
@ -1,2 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from . import models
|
||||
from . import wizard
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@
|
|||
# 'views/membership_membership_line.xml',
|
||||
'views/property_view.xml',
|
||||
'views/res_partner_views.xml',
|
||||
'security/ir.model.access.csv',
|
||||
|
||||
],
|
||||
'demo': [
|
||||
# Reference to demo data files
|
||||
|
|
|
|||
|
|
@ -1 +1,2 @@
|
|||
from . import res_partner
|
||||
from . import res_config_settings
|
||||
|
|
|
|||
12
bemade_sethy_configuration/models/res_config_settings.py
Normal file
12
bemade_sethy_configuration/models/res_config_settings.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from odoo import models, api
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
def set_values(self):
|
||||
res = super().set_values()
|
||||
category_id = self.env.ref('bemade_sethy_configuration.partner_tag_property', raise_if_not_found=False)
|
||||
# If the category_id record exists, we set its ID in ir.config_parameter
|
||||
if category_id:
|
||||
self.env['ir.config_parameter'].sudo().set_param('bemade_sethy_configuration.partner_tag_property', category_id.id)
|
||||
return res
|
||||
|
|
@ -7,6 +7,10 @@ from odoo.addons.website.models import ir_http
|
|||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
|
||||
@api.model
|
||||
def _property_category_id(self):
|
||||
return self.env.ref('bemade_sethy_configuration.partner_tag_property', raise_if_not_found=False)
|
||||
|
||||
surface = fields.Float(string='Surface (ha)') # terrain
|
||||
lot_number = fields.Text(string='Lot Number') # terrain
|
||||
|
||||
|
|
@ -30,6 +34,7 @@ class ResPartner(models.Model):
|
|||
string='Is Property',
|
||||
default=False,
|
||||
compute='_compute_is_property',
|
||||
inverse='_inverse_is_property',
|
||||
store=True
|
||||
) # True if property, False if not
|
||||
|
||||
|
|
@ -55,18 +60,25 @@ class ResPartner(models.Model):
|
|||
string="Property ids"
|
||||
)
|
||||
|
||||
@api.onchange('category_id')
|
||||
@api.depends('category_id')
|
||||
def _compute_is_property(self):
|
||||
property_tag = self.env.ref('bemade_sethy_configuration.partner_tag_property', raise_if_not_found=False)
|
||||
for record in self:
|
||||
for partner 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
|
||||
partner.is_property = False
|
||||
else:
|
||||
record.is_property = record.category_id & property_tag
|
||||
partner.is_property = property_tag and property_tag in partner.category_id
|
||||
|
||||
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 and property_tag not in partner.category_id and property_tag:
|
||||
partner.category_id |= property_tag
|
||||
elif not partner.is_property and property_tag in partner.category_id:
|
||||
partner.category_id -= property_tag
|
||||
|
||||
@api.depends('relation_property_ids')
|
||||
def _compute_property_count(self):
|
||||
|
|
@ -86,7 +98,7 @@ class ResPartner(models.Model):
|
|||
for record in self:
|
||||
record.relation_property_ids = record.relation_all_ids.filtered(
|
||||
lambda line: (
|
||||
line.type_id.name == 'Owner' and line.is_inverse)
|
||||
line.type_id.name == 'Owner' and line.is_inverse)
|
||||
)
|
||||
@api.onchange('lot_number')
|
||||
def _onchange_lot_number(self):
|
||||
|
|
@ -94,39 +106,39 @@ class ResPartner(models.Model):
|
|||
if lot.lot_number:
|
||||
lot.name = "Lot " + str(lot.lot_number)
|
||||
|
||||
# @api.model_create_multi
|
||||
# def create(self, vals_list):
|
||||
# # Get the property tag reference outside the loop to avoid repeated searches.
|
||||
# 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:
|
||||
# # 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
|
||||
def create(self, vals_list):
|
||||
# if 'state_id' not in values or 'country_id' not in values, then set it from the current user's company
|
||||
for vals in vals_list:
|
||||
if 'state_id' not in vals or 'country_id' not in vals:
|
||||
user_company = self.env.user.company_id
|
||||
if 'state_id' not in vals and user_company.state_id:
|
||||
vals['state_id'] = user_company.state_id.id
|
||||
vals['country_id'] = user_company.country_id.id
|
||||
return super(Partner, self).create(vals)
|
||||
# Create Partner records using the super function
|
||||
records = super().create(vals_list)
|
||||
user_company = self.env.user.company_id
|
||||
|
||||
# Update the records where 'state_id' or 'country_id' isn't provided
|
||||
for record in records:
|
||||
if not record.state_id or not record.country_id:
|
||||
if not record.state_id and user_company.state_id:
|
||||
record.write({
|
||||
'state_id': user_company.state_id.id,
|
||||
})
|
||||
if not record.country_id and user_company.country_id:
|
||||
record.write({
|
||||
'country_id': user_company.country_id.id
|
||||
})
|
||||
if record.name.startswith("Lot "):
|
||||
record.lot_number = record.name[4:]
|
||||
record._inverse_is_property()
|
||||
return records
|
||||
|
||||
@api.onchange('name')
|
||||
def _onchange_name(self):
|
||||
for record in self:
|
||||
if record.name and record.name.startswith("Lot "):
|
||||
record.lot_number = record.name[4:]
|
||||
|
||||
def write(self, vals):
|
||||
result = super(ResPartner, self).write(vals)
|
||||
self._inverse_is_property()
|
||||
return result
|
||||
|
||||
@api.onchange('category_id')
|
||||
def _onchange_category_id(self):
|
||||
self._compute_is_property()
|
||||
3
bemade_sethy_configuration/security/ir.model.access.csv
Normal file
3
bemade_sethy_configuration/security/ir.model.access.csv
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_create_property_wizard_salesman,"Access Create Property Wizard Salesman",model_create_property_wizard,sales_team.group_sale_salesman,1,1,1,1
|
||||
access_create_property_wizard_manager,"Access Create Property Wizard Manager",model_create_property_wizard,sales_team.group_sale_manager,1,1,1,1
|
||||
|
|
|
@ -1,6 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="tree_property" model="ir.ui.view">
|
||||
<field name="model">res.partner</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Properties" sample="1" multi_edit="1">
|
||||
<field name="display_name" string="Name"/>
|
||||
<field name="lot_number" optional="show"/>
|
||||
<field name="city" optional="show"/>
|
||||
<field name="zip" optional="show"/>
|
||||
<field name="state_id" optional="hide" readonly="1"/>
|
||||
<field name="country_id" optional="show" readonly="1"/>
|
||||
<field name="category_id" optional="hide" widget="many2many_tags" options="{'color_field': 'color'}"/>
|
||||
<field name="company_id" groups="base.group_multi_company" readonly="1"/>
|
||||
<field name="active" column_invisible="True"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
name="Property"
|
||||
id="menu_property"
|
||||
|
|
@ -13,14 +30,16 @@
|
|||
<field name="name">Properties</field>
|
||||
<field name="res_model">res.partner</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="tree_property"/>
|
||||
<field name="domain">[('is_property','=',True)]</field>
|
||||
<field name="context">{'default_is_property': True}</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
id="menu_property_views"
|
||||
name="Properties"
|
||||
parent="menu_property"
|
||||
action="action_properties"
|
||||
id="menu_property_views"
|
||||
name="Properties"
|
||||
parent="menu_property"
|
||||
action="action_properties"
|
||||
/>
|
||||
|
||||
</odoo>
|
||||
|
|
@ -1,13 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="action_add_property" model="ir.actions.act_window">
|
||||
<field name="name">Add Property</field>
|
||||
<field name="res_model">create.property.wizard</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<record id="partner_default_contacts_view_form" model="ir.ui.view">
|
||||
<field name="name">bemade_sethy_configuration.res_partner.defaults.form</field>
|
||||
<field name="model">res.partner</field>
|
||||
<field name="inherit_id" ref="base.view_partner_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="company_type" position="after">
|
||||
<field name="is_property" invisible="True"/>
|
||||
<field name="is_property" invisible="False"/>
|
||||
</field>
|
||||
|
||||
<xpath expr="//field[@name='name' and @id='company']" position="replace">
|
||||
|
|
@ -65,46 +72,52 @@
|
|||
|
||||
<xpath expr="//page[@name='contact_addresses']" position="after">
|
||||
<page string="Property" name="bemade_sethy_configuration.res_partner.defaults.form">
|
||||
<group string="All Owners" invisible="is_property == False">
|
||||
<field name="relation_property_ids" string="">
|
||||
<tree editable="top">
|
||||
<field name="this_partner_id" required="True" options="{'no_create': True}"
|
||||
invisible="1"/>
|
||||
<field name="type_selection_id" required="True" options="{'no_create': True}"
|
||||
invisible="1"/>
|
||||
<field name="other_partner_id" required="True" options="{'no_create': True}"
|
||||
string="Owner"/>
|
||||
<field name="date_start"/>
|
||||
<field name="date_end"/>
|
||||
<field name="active" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
<group string="All Properties" invisible="is_property == True">
|
||||
<field name="relation_owner_ids" string="">
|
||||
<tree editable="top">
|
||||
<field name="this_partner_id" required="True"
|
||||
options="{'no_create': True}"
|
||||
invisible="1"
|
||||
/>
|
||||
<field name="type_selection_id" required="True" options="{'no_create': True}"
|
||||
invisible="1"/>
|
||||
<field name="other_partner_id" required="True" options="{'no_create': True}"
|
||||
string="Property"/>
|
||||
<field name="date_start"/>
|
||||
<field name="date_end"/>
|
||||
<field name="active" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
<field name="relation_property_ids" string="All Owners" invisible="is_property == False">
|
||||
<tree editable="top">
|
||||
<field name="this_partner_id"
|
||||
required="True"
|
||||
options="{'no_create': True}"
|
||||
invisible="1"/>
|
||||
<field name="type_selection_id"
|
||||
required="True"
|
||||
options="{'no_create': True}"
|
||||
invisible="1"/>
|
||||
<field name="other_partner_id"
|
||||
required="True"
|
||||
options="{'no_create': True}"
|
||||
string="Owner"/>
|
||||
<field name="date_start"/>
|
||||
<field name="date_end"/>
|
||||
<field name="active" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
<field name="relation_owner_ids" string="All Properties" invisible="is_property == True">
|
||||
<tree editable="top">
|
||||
<field name="this_partner_id" required="True"
|
||||
options="{'no_create': True}"
|
||||
invisible="1"
|
||||
/>
|
||||
<field name="type_selection_id" required="True" options="{'no_create': True}"
|
||||
invisible="1"/>
|
||||
<field name="other_partner_id" required="True" options="{'no_create': True}"
|
||||
string="Property"/>
|
||||
<field name="date_start"/>
|
||||
<field name="date_end"/>
|
||||
<field name="active" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button name="%(action_add_property)d"
|
||||
type="action"
|
||||
class="oe_highlight"
|
||||
string="Add Property" />
|
||||
</page>
|
||||
</xpath>
|
||||
<xpath expr="//page[@name='contact_addresses']" position="after">
|
||||
<page string="Sethy" name="bemade_sethy_configuration.res_partner.page.sethy">
|
||||
<group>
|
||||
<field name="ref_project"/>
|
||||
<field name="intent_signing"/>
|
||||
<field name="cyberimpact"/>
|
||||
<field name="intent_signing" invisible="is_property"/>
|
||||
<field name="cyberimpact" invisible="is_property"/>
|
||||
<field name="specification_date"/>
|
||||
<field name="crm_stage_activity"/>
|
||||
</group>
|
||||
|
|
@ -125,5 +138,15 @@
|
|||
<!-- </field>-->
|
||||
<!-- </record>-->
|
||||
|
||||
<record id="contacts.action_contacts" model="ir.actions.act_window">
|
||||
<field name="name">Contacts</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">res.partner</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<!-- Add your domain here -->
|
||||
<field name="domain">[('is_property','=',False)]</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
</odoo>
|
||||
1
bemade_sethy_configuration/wizard/__init__.py
Normal file
1
bemade_sethy_configuration/wizard/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from . import create_property_wizard
|
||||
10
bemade_sethy_configuration/wizard/create_property_wizard.py
Normal file
10
bemade_sethy_configuration/wizard/create_property_wizard.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
from odoo import models, fields, api
|
||||
|
||||
class CreatePropertyWizard(models.TransientModel):
|
||||
_name = 'create.property.wizard'
|
||||
|
||||
property_id = fields.Many2one('res.partner', string='Property', domain=[('is_property', '=', True)])
|
||||
|
||||
def action_done(self):
|
||||
# Here process your data, for example:
|
||||
self.env['res.partner'].browse(self._context.get('active_ids')).write({'property_id': self.property_id.id})
|
||||
10
bemade_sethy_configuration/wizard/select_property_wizard.py
Normal file
10
bemade_sethy_configuration/wizard/select_property_wizard.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
from odoo import models, fields, api
|
||||
|
||||
class AddPropertyWizard(models.TransientModel):
|
||||
_name = 'add.property.wizard'
|
||||
|
||||
property_id = fields.Many2one('res.partner', string='Property', domain=[('is_property', '=', True)])
|
||||
|
||||
def action_done(self):
|
||||
# Here process your data, for example:
|
||||
self.env['res.partner'].browse(self._context.get('active_ids')).write({'property_id': self.property_id.id})
|
||||
Loading…
Reference in a new issue