Skip to content
Extraits de code Groupes Projets
Valider 3c0c170d rédigé par Benjamin - Le Filament's avatar Benjamin - Le Filament
Parcourir les fichiers

[FIX] constrains error

parent 41a816d5
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -13,9 +13,7 @@ class CompanyShareLine(models.Model): ...@@ -13,9 +13,7 @@ class CompanyShareLine(models.Model):
# ------------------------------------------------------ # ------------------------------------------------------
# Fields declaration # Fields declaration
# ------------------------------------------------------ # ------------------------------------------------------
share_number = fields.Integer( share_number = fields.Integer(string="Number of Share", required=True)
string="Number of Share", required=True
)
share_unit_price = fields.Monetary( share_unit_price = fields.Monetary(
string="Share price", string="Share price",
currency_field="company_currency_id", currency_field="company_currency_id",
......
...@@ -19,16 +19,20 @@ class ResCompany(models.Model): ...@@ -19,16 +19,20 @@ class ResCompany(models.Model):
# ------------------------------------------------------ # ------------------------------------------------------
# Constraints # Constraints
# ------------------------------------------------------ # ------------------------------------------------------
@api.constrains( @api.constrains("company_share_line_ids",)
"company_share_line_ids",
"company_share_line_ids.share_count",
"company_share_line_ids.company_id",
)
def _check_share_line(self): def _check_share_line(self):
for company in self: for company in self:
company_share_line = company.company_share_line_ids company_share_line = company.company_share_line_ids
share_in = sum(company_share_line(lambda s: s.share_action == "purchase")) share_in = sum(
share_out = sum(company_share_line(lambda s: s.share_action == "refund")) company_share_line.filtered(
lambda s: s.share_action == "purchase"
).mapped("share_number")
)
share_out = sum(
company_share_line.filtered(
lambda s: s.share_action == "refund"
).mapped("share_number")
)
if share_out > share_in: if share_out > share_in:
raise ValidationError(_("You cannot refund more shares that you have.")) raise ValidationError(_("You cannot refund more shares that you have."))
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter