Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
286 Ansichten

i odoo mrp i have custom addons that inherit the mrp production and add some logic to the action_confirm button as follow:

def action_confirm(self):
res = super(MrpProduction, self).action_confirm()
for rec in self:
if not rec.division_line:
raise ValidationError(_("Add Division"))
if not rec.location_confirm:
raise ValidationError("Confirm Location ")
​return res
# In other custom addons i need to inherit the same function and modify this if condition, i added the custom module in the depends in my other custom module and then call the same function and modify the if statement but still the raise executed from the first inherited function
Avatar
Verwerfen
Beste Antwort

Hi,


In Odoo, multiple modules override the same method (action_confirm), but Odoo only executes the method from the last-loaded module unless they are chained properly using super().


In your case, the second custom module overrides action_confirm, but the super() call refers only to mrp.production, not to the previously customized version in your first module.


Make sure both custom modules call super() correctly, so Odoo can chain all overrides.


Module 1


class MrpProduction(models.Model):
_inherit = 'mrp.production'

def action_confirm(self):
res = super().action_confirm()
for rec in self:
if not rec.division_line:
raise ValidationError(_("Add Division"))
if not rec.location_confirm:
raise ValidationError("Confirm Location")
return res


Module 2


class MrpProduction(models.Model):
_inherit = 'mrp.production'

def action_confirm(self):
res = super().action_confirm()
# You can add your conditions here
return res



In Module 2, add Module 1 in the depends list in the __manifest__.py.--


Hope it helps.

Avatar
Verwerfen
Beste Antwort

Multiple approaches, depends on what you need to do. In your other module, you could do the super() call in an else condition to execute only if your conditions to process differently are not met:

def action_confirm(self):
​ if your_condition:
for rec in self:
​ self.do_your_stuff()
​ else:
return super(MrpProduction, self).action_confirm()

Or, for example, apply a context that can be checked where/whenever needed:

# Module A
def action_confirm(self):
self = self.with_context(some_speaking_key=True)
res = super(MrpProduction, self).action_confirm()
for rec in self:
if not rec.division_line:
raise ValidationError(_("Add Division"))
if not rec.location_confirm:
raise ValidationError("Confirm Location ")
​return res

# Module B
def action_confirm(self):
if self._context.get('some_speaking_key'):
...




Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
2
Dez. 22
11893
0
März 15
4535
2
Juni 21
5487
1
Sept. 24
4110
2
Juni 15
9073