Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
1535 Näkymät

I have create and write method in project.project model , the problem is the create function always give me user error in any situation and does not work well unless i comment out the write function . 

@api.model

defcreate(self, vals):

fdi = vals.get('soucre_fund_FDI',0)

ddi = vals.get('soucre_fund_DDI',0)

gov = vals.get('soucre_fund_GOV',0)
​total = fdi + ddi + gov

​iftotal != 100:

​raise UserError(_("The total of Source of fund (FDI %), Source of fund (DDI ​%), and Source of fund (GOV %) must equal 100."))
​self.clear_caches()

​returnsuper(Project, self).create(vals)


defwrite(self, vals):

fdi = vals.get('soucre_fund_FDI', self.soucre_fund_FDI)

ddi = vals.get('soucre_fund_DDI', self.soucre_fund_DDI)

gov = vals.get('soucre_fund_GOV', self.soucre_fund_GOV)
​total = fdi + ddi + goviftotal != 100:raise UserError(_("The total of Source of fund ​(FDI %), Source of fund (DDI %), and Source of fund (GOV %) must equal 100."))
​self.clear_caches()

​returnsuper(Project, self).write(vals)

Avatar
Hylkää
Tekijä Paras vastaus

i solved it by add a if statement to the write function.

def write(self, vals):

​if 'soucre_fund_FDI' in vals or 'soucre_fund_DDI' in vals or 'soucre_fund_GOV' in ​vals:

​fdi = vals.get('soucre_fund_FDI', self.soucre_fund_FDI)

​ddi = vals.get('soucre_fund_DDI', self.soucre_fund_DDI)

​gov = vals.get('soucre_fund_GOV', self.soucre_fund_GOV)
​total = fdi + ddi + gov

​if total != 100:

​raise UserError(_("The total of Source of fund (FDI %), Source of fund (DDI %), and ​Source of fund (GOV %) ​must equal 100."))

​self.clear_caches()

​return super(Project, self).write(vals)

Avatar
Hylkää
Paras vastaus

Dear Mazinsali,


I think you need give space before function definition like this def create and def write

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
kesäk. 20
34526
1
marrask. 17
2696
1
kesäk. 16
4136
2
elok. 15
4925
1
elok. 23
2440