10000 [IMP] estate: Chapter 13 · odoo/tutorials@6a42330 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a42330

Browse files
xafr-odoosedi-odoo
andcommitted
[IMP] estate: Chapter 13
Inter-module interactions Optimized code to correct a DRY violation that led to unnecessary calls and wasted compute power. Co-authored-by: Sébastien Dieu <118258604+sedi-odoo@users.noreply.github.com>
1 parent 3ebcdc6 commit 6a42330

File tree

11 files changed

+18
-14
lines changed

11 files changed

+18
-14
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# PyCharm Demo Config
132+
.run/rd-demo.run.xml

.run/rd-demo.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<option name="ADD_SOURCE_ROOTS" value="true" />
1515
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
1616
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/../../../worktrees/saas-18.3/odoo/odoo-bin" />
17-
<option name="PARAMETERS" value="-c $PROJECT_DIR$/.odev/training_odoo.conf -u awesome_owl,awesome_clicker,awesome_gallery,awesome_dashboard,awesome_kanban,estate" />
17+
<option name="PARAMETERS" value="-c $PROJECT_DIR$/.odev/training_odoo.conf -u awesome_owl,awesome_clicker,awesome_gallery,awesome_dashboard,awesome_kanban,estate,estate_account" />
1818
<option name="SHOW_COMMAND_LINE" value="false" />
1919
<option name="EMULATE_TERMINAL" value="true" />
2020
<method v="2" />

awesome_gallery/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'summary': """
55
Starting module for "Master the Odoo web framework, chapter 3: Create a Gallery View"
66
""",
7-
'author': "unknown",
7+
'author': "odoo",
88
'description': """
99
Starting module for "Master the Odoo web framework, chapter 3: Create a Gallery View"
1010
""",

awesome_kanban/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'summary': """
55
Starting module for "Master the Odoo web framework, chapter 4: Customize a kanban view"
66
""",
7-
'author': "unknown",
7+
'author': "odoo",
88
'description': """
99
Starting module for "Master the Odoo web framework, chapter 4: Customize a kanban view.
1010
""",

estate/data/estate_menus.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<menuitem id="estate_property_settings_menu" name="Settings">
88
<menuitem id="estate_property_type_model_menu_action" action="estate_property_type_model_action"/>
99
<menuitem id="estate_property_tag_model_menu_action" action="estate_property_tag_model_action"/>
10-
<menuitem id="inherited_users_model_menu_action" action="inherited_users_action"/>
1110
</menuitem>
1211
</menuitem>
1312
</odoo>

estate/models/estate_property_offer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ def action_btn_refuse(self):
4343

4444
@api.model_create_multi
4545
def create(self, vals_list):
46+
estate_properties = self.env["estate.property"].browse([vals['property_id'] for vals in vals_list if vals['property_id']])
4647
for vals in vals_list:
47-
self.env['estate.property'].browse(vals['property_id']).state = 'offer_received'
48-
if vals['price'] < self.env['estate.property'].browse(vals['property_id']).best_offer:
48+
if not vals["property_id"]:
49+
continue
50+
estate_property = estate_properties.filtered(lambda ep: ep.id == vals['property_id'])[:1]
51+
estate_property.state = 'offer_received'
52+
if vals['price'] < estate_property.best_offer:
4953
raise UserError("Can't make a smaller offer than the best one currently recorded!")
5054
return super().create(vals_list)

estate/models/estate_property_type.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
class EstatePropertyType(models.Model):
55
_name = 'estate.property.type'
66
_description = 'Estate property type'
7-
_order = "manual_ordering asc, name asc"
7+
_order = "sequence asc, name asc"
88

99
_type_name_uniq = (models.Constraint("""UNIQUE (name)""",
1010
"The type name must be unique."))
1111

1212
name = fields.Char('Title', required=True, translate=True)
1313
line_ids = fields.One2many("estate.property", "property_type_id")
14-
manual_ordering = fields.Integer('Sequence', default=1, help="Used to order stages. Lower is better.")
14+
sequence = fields.Integer('Sequence', default=1, help="Used to order stages. Lower is better.")
1515
offer_ids = fields.One2many("estate.property.offer", "property_type_id")
16-
offer_count = fields.Integer(compute='_compute_offers')
16+
offer_count = fields.Integer(compute='_compute_offer_count')
1717

1818
@api.depends("offer_ids")
19-
def _compute_offers(self):
19+
def _compute_offer_count(self):
2020
for record in self:
2121
record.offer_count = len(record.offer_ids)

estate/models/res_users.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
class ResUsers(models.Model):
55
_inherit = "res.users"
66

7-
property_ids = fields.One2many("estate.property", "salesman_id", domain="")
7+
property_ids = fields.One2many("estate.property", "salesman_id", domain="[('state', 'in', ['new', 'offer_received'])]")

estate/views/estate_property_type_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<field name="model">estate.property.type</field>
5353
<field name="arch" type="xml">
5454
<list>
55-
<field name="manual_ordering" widget="handle"/>
55+
<field name="sequence" widget="handle"/>
5656
<field name="name"/>
5757
<field name="line_ids"/>
5858
<field name="offer_ids"/>

estate/views/res_users_views.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<field name="name">Users &amp; Companies</field>
55
<field name="res_model">res.users</field>
66
<field name="view_mode">list,form</field>
7-
<field name="context">{'search_default_availability': True}</field>
87
</record>
98

109
<record id="view_users_form" model="ir.ui.view">

0 commit comments

Comments
 (0)
0