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

Technical Training Solution #59

Open
wants to merge 128 commits into
base: master
Choose a base branch
from
Open

Technical Training Solution #59

wants to merge 128 commits into from

Conversation

goeko
Copy link

@goeko goeko commented Nov 7, 2023

No description provided.

@goeko goeko closed this Nov 7, 2023
@goeko goeko reopened this Nov 7, 2023
@goeko goeko marked this pull request as ready for review November 7, 2023 15:19
@goeko goeko marked this pull request as draft November 7, 2023 15:19
@goeko goeko marked this pull request as ready for review November 7, 2023 15:21
@goeko
Copy link
Author

goeko commented Nov 7, 2023

@sts-odoo

@goeko
Copy link
Author

goeko commented Nov 7, 2023

@sts-odoo technical training on ODX 2023

@FalcoBolger FalcoBolger requested a review from sts-odoo November 7, 2023 15:23
Comment on lines +14 to +15
expected_price = fields.Float(required=True)
selling_price = fields.Float(required=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't covered it on purpose, but for your information, in odoo there is a type of field Monetary, see https://www.odoo.com/documentation/17.0/developer/reference/backend/orm.html#odoo.fields.Monetary

name = fields.Char()
description = fields.Text()
postcode = fields.Char()
date_availability = fields.Date(default=lambda self: fields.Date.today() + relativedelta(months=+3))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may also use the method defined on the field type Date:

Suggested change
date_availability = fields.Date(default=lambda self: fields.Date.today() + relativedelta(months=+3))
date_availability = fields.Date(default=lambda self: fields.Date.add(fields.Date.today(), months=3))

property_type_id = fields.Many2one("estate.property.type")
seller_id = fields.Many2one("res.partner", string="Seller")
buyer_id = fields.Many2one("res.partner", string="Buyer")
tag_ids = fields.Many2many("estate.property.tag", string="Tags")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In most cases it is not necessary, but not that on M2m fields we can define manually the name of the table used in between the 2 models. It is especially useful when multiple m2m fields exists between the same models. See relation in
https://www.odoo.com/documentation/17.0/developer/reference/backend/orm.html#odoo.fields.Many2many

In this particular case it's not an issue

Comment on lines +53 to +59
def _onchange_garden(self):
if self.garden == 1:
self.garden_area = 10
self.garden_orientation = "north"
else:
self.garden_area = 0
self.garden_orientation = ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.garden is a Boolean field, so self.garden == 1 will always be False

Suggested change
def _onchange_garden(self):
if self.garden == 1:
self.garden_area = 10
self.garden_orientation = "north"
else:
self.garden_area = 0
self.garden_orientation = ""
def _onchange_garden(self):
if self.garden:
self.garden_area = 10
self.garden_orientation = "north"
else:
self.garden_area = 0
self.garden_orientation = False

Comment on lines +30 to +33
if record.create_date:
record.date_deadline = record.create_date + relativedelta(days=record.validity)
else:
record.date_deadline = fields.Date.today() + relativedelta(days=record.validity)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if record.create_date:
record.date_deadline = record.create_date + relativedelta(days=record.validity)
else:
record.date_deadline = fields.Date.today() + relativedelta(days=record.validity)
create_date = record.create_date or fields.Date.today()
record.date_deadline = create_date + relativedelta(days=record.validity)

Comment on lines +36 to +40
for record in self:
if record.create_date:
record.validity = (record.date_deadline - record.create_date.date()).days
else:
record.validity = (record.date_deadline - fields.Date.today()).days
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

<field name="price"/>
<field name="date_deadline"/>
<field name="status"/>
<!-- <field name="property_type_id" invisible="1"/> <!- - make the field invisible, it do not need show to the user. leave it as learning stuff. -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some time it is necessary to have fields invisible just for the purpose of using them in other fields attributes, see https://www.odoo.com/documentation/17.0/developer/reference/user_interface/view_architecture.html#python-expression

</page>
<page string="Offers">
<group>
<field name="offer_ids"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 2many fields you can define the view in place here:

Suggested change
<field name="offer_ids"/>
<field name="offer_ids">
<tree>
<field name="name"/>
<field name="partner_id"/>
<field name="validity"/>
<field name="price"/>
<field name="date_deadline"/>
<field name="status"/>
<button name="estate_property_offer_accepted_action" string="Accepted" type="object" icon="fa-check"/>
<button name="estate_property_offer_refused_action" string="Refused" type="object" icon="fa-level-down"/>
</tree>
</field>

if you do not define in place it will look for the view define somewhere else. This would make sense mainly on One2many since most of the time the child record is meaningless without the parent.

@sts-odoo sts-odoo force-pushed the master branch 2 times, most recently from 6c0c381 to bee08e9 Compare November 30, 2023 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants