콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

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
아바타
취소
베스트 답변

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.

아바타
취소
베스트 답변

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'):
...




아바타
취소
관련 게시물 답글 화면 활동
2
12월 22
11919
0
3월 15
4537
2
6월 21
5500
1
9월 24
4134
2
6월 15
9077