67 lines
2.1 KiB
Python
67 lines
2.1 KiB
Python
|
from netforce.model import Model, fields, get_model
|
||
|
from netforce.utils import get_data_path
|
||
|
|
||
|
class MatchingPaymentGroup(Model):
|
||
|
_name="clinic.matching.payment.group"
|
||
|
_string="Matching Payment Group"
|
||
|
|
||
|
def _get_all(self,ids,context={}):
|
||
|
res={}
|
||
|
for obj in self.browse(ids):
|
||
|
total=0
|
||
|
for line in obj.lines:
|
||
|
matching=line.matching_id
|
||
|
for mline in matching.lines:
|
||
|
total+=mline.fee or 0
|
||
|
total+=mline.srv or 0
|
||
|
total+=mline.epo or 0
|
||
|
res[obj.id]={
|
||
|
'total': total,
|
||
|
}
|
||
|
return res
|
||
|
|
||
|
_fields={
|
||
|
'name': fields.Char("Name",required=True),
|
||
|
'lines': fields.One2Many("clinic.matching.payment.group.line","group_matching_id", "Lines"),
|
||
|
'total': fields.Float("Total",function="_get_all",function_multi=True),
|
||
|
'state': fields.Selection([['draft','Draft'],['approved','Approved']],'State'),
|
||
|
}
|
||
|
|
||
|
_defaults={
|
||
|
'state': 'draft',
|
||
|
}
|
||
|
|
||
|
def post(self,ids,context={}):
|
||
|
for obj in self.browse(ids):
|
||
|
print("%s posted"%(obj.id))
|
||
|
return {
|
||
|
'next': {
|
||
|
'name': 'clinic_matching_payment_group',
|
||
|
'mode': 'form',
|
||
|
'active_id': obj.id,
|
||
|
},
|
||
|
'flash': 'Posted',
|
||
|
}
|
||
|
|
||
|
def update_amount(self,context={}):
|
||
|
data=context['data']
|
||
|
data['total']=0
|
||
|
for line in data['lines']:
|
||
|
data['total']+=line['amount'] or 0
|
||
|
return data
|
||
|
|
||
|
def onchange_matching(self,context={}):
|
||
|
data=context['data']
|
||
|
path=context['path']
|
||
|
line=get_data_path(data,path,parent=True)
|
||
|
matching_id=line['matching_id']
|
||
|
matching=get_model('clinic.matching.payment').browse(matching_id)
|
||
|
line['srv']=matching['total_srv'] or 0
|
||
|
line['epo']=matching['total_epo'] or 0
|
||
|
line['fee']=matching['total_fee'] or 0
|
||
|
line['amount']=line['fee']+line['epo']+line['srv']
|
||
|
data=self.update_amount(context=context)
|
||
|
return data
|
||
|
|
||
|
MatchingPaymentGroup.register()
|