Skip to content

Commit

Permalink
[REF] chap15: should meet all the guidline rule (hopefully)
Browse files Browse the repository at this point in the history
  • Loading branch information
lipiraux committed Oct 24, 2024
1 parent 2b18b68 commit 0086d8d
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 48 deletions.
2 changes: 1 addition & 1 deletion estate/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
],
'license': "LGPL-3",
'demo': [
"demo/demo.xml",
"data/demo.xml",
],
}
File renamed without changes.
48 changes: 29 additions & 19 deletions estate/models/estate_property_offer.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
from datetime import timedelta
from odoo import api, fields, models, _
from odoo import _, api, fields, models
from odoo.exceptions import UserError


class PropertyOffer(models.Model):
_name = 'estate.property.offer'
_name = "estate.property.offer"
_description = "Property offer"

_sql_constraints = [
('check_positive_offer_price', 'CHECK(price > 0)', "The offer price must be strictly positive."),
(
"check_positive_offer_price",
"CHECK(price > 0)",
"The offer price must be strictly positive.",
),
]
_order = "price desc"

price = fields.Float(string="Price")
status = fields.Selection(
string="Status",
selection=[('accepted', "Accepted"), ('refused', "Refused")],
selection=[("accepted", "Accepted"), ("refused", "Refused")],
copy=False,
)
partner_id = fields.Many2one('res.partner', string="Partner", required=True)
property_id = fields.Many2one('estate.property', string="Property", required=True)
partner_id = fields.Many2one("res.partner", string="Partner", required=True)
property_id = fields.Many2one("estate.property", string="Property", required=True)
validity = fields.Integer(string="Validiy (days)", default=7)
date_deadline = fields.Date(
string="Deadline Date",
compute='_compute_date_deadline',
inverse='_inverse_date_deadline',
compute="_compute_date_deadline",
inverse="_inverse_date_deadline",
)
property_type_id = fields.Many2one(
"estate.property.type",
string="Property Type",
related="property_id.property_type_id",
)
property_type_id = fields.Many2one('estate.property.type', string="Property Type", related='property_id.property_type_id')

@api.depends('create_date', 'validity')
@api.depends("create_date", "validity")
def _compute_date_deadline(self):
for offer in self:
create_date = offer.create_date or fields.Datetime.now()
Expand All @@ -41,30 +49,32 @@ def _inverse_date_deadline(self):

def action_accept_offer(self):
for offer in self:
if offer.status == 'accepted':
if offer.status == "accepted":
raise UserError(_("You already accepted the offer."))
if offer.property_id.buyer_id:
raise UserError(_("Only one offer can be accepted."))
offer.status = 'accepted'
offer.status = "accepted"
offer.property_id.selling_price = offer.price
offer.property_id.buyer_id = offer.partner_id
for property_offer in offer.property_id.offer_ids:
if property_offer.id != offer.id:
offer.status = 'refused'
offer.status = "refused"
return True

def action_refuse_offer(self):
for offer in self:
if offer.status == 'accepted':
raise UserError(_("You cannot refuse an offer once it has been accepted."))
offer.status = 'refused'
if offer.status == "accepted":
raise UserError(
_("You cannot refuse an offer once it has been accepted.")
)
offer.status = "refused"

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
property_id = self.env['estate.property'].browse(vals['property_id'])
price = vals['price']
property_id = self.env["estate.property"].browse(vals["property_id"])
price = vals["price"]
if any(prev_offer.price > price for prev_offer in property_id.offer_ids):
raise UserError(_("An offer with an higher price already exists."))
property_id.state = 'offer_received'
property_id.state = "offer_received"
return super().create(vals_list)
4 changes: 2 additions & 2 deletions estate/views/estate_menus.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0"?>
<odoo>
<menuitem id="estate_property_root" name="Real Estate">
<menuitem id="estate_property_menu" name="Real Estate">
<menuitem id="estate_property_menu_advertisments" name="Advertisements">
<menuitem id="estate_property_properties_menu" name="Properties" action="estate.estate_property_action"/>
<menuitem id="estate_property_menu_properties" name="Properties" action="estate.estate_property_action"/>
</menuitem>
<menuitem id="estate_property_menu_settings" name="Settings">
<menuitem id="estate_property_type_menu" name="Property Types" action="estate.estate_property_type_action"/>
Expand Down
1 change: 0 additions & 1 deletion estate/views/estate_property_tag_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@
</list>
</field>
</record>

</odoo>
2 changes: 0 additions & 2 deletions estate/views/estate_property_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,4 @@
</kanban>
</field>
</record>


</odoo>
4 changes: 2 additions & 2 deletions estate/views/res_users_views.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<odoo>
<record id="view_users_form_estate" model="ir.ui.view">
<field name="name">res.users.form.estate</field>
<record id="res_users_view_form" model="ir.ui.view">
<field name="name">res.users.view.form.inherit.estate.property</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">
Expand Down
46 changes: 25 additions & 21 deletions estate_account/models/estate_property.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
from odoo import Command, models, _
from odoo import Command, _, models
from odoo.exceptions import MissingError


class EstateProperty(models.Model):
_inherit = 'estate.property'
_inherit = "estate.property"

def action_sold(self):
journal = self.env['account.journal'].search([('type', '=', 'sale')], limit=1)
journal = self.env["account.journal"].search([("type", "=", "sale")], limit=1)
if not journal:
raise MissingError(_("Missing sales journal."))
invoice_vals_list = []
for estate in self:
invoice_line_ids = [
Command.create({
'name': estate.name,
'quantity': 1,
'price_unit': estate.selling_price * 0.06,
}),
Command.create({
'name': "Administrative fees",
'quantity': 1,
'price_unit': 100.0,
})
]
invoice_vals = {
'move_type': 'out_invoice',
'invoice_user_id': estate.salesman_id.id,
'partner_id': estate.buyer_id.id,
'journal_id': journal.id,
'invoice_line_ids': invoice_line_ids,
"move_type": "out_invoice",
"invoice_user_id": estate.salesman_id.id,
"partner_id": estate.buyer_id.id,
"journal_id": journal.id,
"invoice_line_ids": [
Command.create(
{
"name": estate.name,
"quantity": 1,
"price_unit": estate.selling_price * 0.06,
}
),
Command.create(
{
"name": "Administrative fees",
"quantity": 1,
"price_unit": 100.0,
}
),
],
}
invoice_vals_list.append(invoice_vals)
self.env['account.move'].create(invoice_vals_list)
self.env["account.move"].create(invoice_vals_list)
return super().action_sold()

0 comments on commit 0086d8d

Please sign in to comment.