@@ -50,18 +50,18 @@ class EstateProperty(models.Model):
5050 best_price = fields .Float (compute = "_compute_best_price" , string = "Best Offer" , store = True )
5151 validity_days = fields .Integer (default = 7 )
5252 date_deadline = fields .Date (compute = "_compute_date_deadline" , inverse = "_inverse_date_deadline" , store = True )
53-
53+
5454 _check_price = models .Constraint (
5555 'CHECK(expected_price > 0 AND selling_price >= 0)' ,
5656 'The Price of a property must be strictly positive.' ,
5757 )
58-
58+
5959 @api .depends ("living_area" , "garden_area" )
6060 def _compute_total_area (self ):
6161 for record in self :
6262 record .total_area = (record .living_area or 0 ) + (record .garden_area or 0 )
6363
64- @api .depends ("offer_ids.price" , "state" )
64+ @api .depends ("offer_ids.price" , "state" )
6565 def _compute_best_price (self ):
6666 for record in self :
6767 record .best_price = max (record .offer_ids .mapped ("price" )) if record .offer_ids else 0.0
@@ -91,16 +91,22 @@ def _onchange_garden(self):
9191 else :
9292 record .garden_area = 0
9393 record .garden_orientation = False
94-
94+
95+ @api .model
96+ def create (self , vals ):
97+ record = super ().create (vals )
98+ if record .offer_ids :
99+ record .state = 'offer_received'
100+ return record
101+
95102 def write (self , vals ):
103+ res = super ().write (vals )
96104 if 'offer_ids' in vals :
97- result = super ().write (vals )
98105 for record in self :
99- if record .offer_ids and record .state == 'new ' :
106+ if record .offer_ids and record .state != 'offer_received ' :
100107 record .state = 'offer_received'
101- return result
102- return super ().write (vals )
103-
108+ return res
109+
104110 def action_set_sold (self ):
105111 for record in self :
106112 record .state = "sold"
0 commit comments