-
Notifications
You must be signed in to change notification settings - Fork 748
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
base: master
Are you sure you want to change the base?
Conversation
@sts-odoo technical training on ODX 2023 |
expected_price = fields.Float(required=True) | ||
selling_price = fields.Float(required=True) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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:
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") |
There was a problem hiding this comment.
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
def _onchange_garden(self): | ||
if self.garden == 1: | ||
self.garden_area = 10 | ||
self.garden_orientation = "north" | ||
else: | ||
self.garden_area = 0 | ||
self.garden_orientation = "" |
There was a problem hiding this comment.
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
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 |
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
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 |
There was a problem hiding this comment.
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. --> |
There was a problem hiding this comment.
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"/> |
There was a problem hiding this comment.
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:
<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.
6c0c381
to
bee08e9
Compare
No description provided.