109 lines
4.0 KiB
Python
109 lines
4.0 KiB
Python
|
import time
|
||
|
from calendar import monthrange
|
||
|
|
||
|
from netforce.model import Model, fields, get_model
|
||
|
|
||
|
class PaymentMatching(Model):
|
||
|
_name="clinic.payment.matching"
|
||
|
_string="Payment Matching"
|
||
|
_transient=True
|
||
|
|
||
|
|
||
|
_fields={
|
||
|
'name': fields.Char("Name"),
|
||
|
"date": fields.Date("Month"),
|
||
|
"date_from": fields.Date("From", required=True),
|
||
|
"date_to": fields.Date("To", required=True),
|
||
|
'file_id': fields.Many2One('document','File',domain=[['categ_id.code','=','MP']]),
|
||
|
"period_id": fields.Many2One("clinic.period.line","Period"),
|
||
|
'department_id': fields.Many2One("clinic.department","Department"),
|
||
|
'branch_id': fields.Many2One("clinic.branch","Branch"),
|
||
|
"inv_state": fields.Selection([("draft","Draft"),("waiting_approval","Waiting Approval"),("waiting_payment","Waiting Payment"),("paid","Paid"),("voided","Voided")],"Status"),
|
||
|
"view_type": fields.Selection([("invoice","Invoice"),("file","File")],"View Type"),
|
||
|
}
|
||
|
|
||
|
def _get_date_from(self,context={}):
|
||
|
year,month,day=time.strftime("%Y-%m-%d").split("-")
|
||
|
return '%s-%s-%s'%(year,month,day)
|
||
|
|
||
|
def _get_date_to(self,context={}):
|
||
|
year,month,day=time.strftime("%Y-%m-%d").split("-")
|
||
|
weekday, total_day=monthrange(int(year), int(month))
|
||
|
return "%s-%s-%s"%(year,month,day)
|
||
|
|
||
|
def default_get(self,field_names=None,context={},**kw):
|
||
|
defaults=context.get("defaults",{})
|
||
|
date_from=defaults.get("date_from", self._get_date_from())
|
||
|
date_to=defaults.get("date_to", self._get_date_to())
|
||
|
yearnow=date_from.split("-")[0]
|
||
|
for period in get_model('clinic.period').search_browse([['name','=',yearnow]]):
|
||
|
for line in period.lines:
|
||
|
if line.state=='open':
|
||
|
period_id=line.id
|
||
|
date_from=line.date_start
|
||
|
date_to=line.date_stop
|
||
|
break
|
||
|
res={
|
||
|
'period_id': period_id,
|
||
|
'date': time.strftime("%Y-%m-%d"),
|
||
|
'date_from': date_from,
|
||
|
'date_to': date_to,
|
||
|
'inv_state': 'waiting_payment',
|
||
|
'view_type': 'invoice',
|
||
|
}
|
||
|
return res
|
||
|
|
||
|
def onchange_period(self,context={}):
|
||
|
data=context['data']
|
||
|
period_id=data['period_id']
|
||
|
period=get_model('clinic.period.line').browse(period_id)
|
||
|
data['date_from']=period.date_start
|
||
|
data['date_to']=period.date_stop
|
||
|
return data
|
||
|
|
||
|
def get_report_data(self,ids,context={}):
|
||
|
defaults=self.default_get(context=context)
|
||
|
print('defaults ', defaults)
|
||
|
date_from=defaults.get('date_from')
|
||
|
date_to=defaults.get('date_to')
|
||
|
branch_id=None
|
||
|
department_id=None
|
||
|
inv_state=defaults.get('inv_state')
|
||
|
view_type=defaults.get('view_type')
|
||
|
if ids:
|
||
|
obj=self.browse(ids)[0]
|
||
|
date_from=obj.date_from
|
||
|
date_to=obj.date_to
|
||
|
branch_id=obj.branch_id.id
|
||
|
department_id=obj.department_id.id
|
||
|
inv_state=obj.inv_state
|
||
|
view_type=obj.view_type
|
||
|
lines=[]
|
||
|
dom=[
|
||
|
['date','>=',date_from],
|
||
|
['date','<=',date_to],
|
||
|
['state','=',inv_state],
|
||
|
]
|
||
|
if branch_id and not department_id:
|
||
|
dom.append(['department_id.branch_id','=',branch_id])
|
||
|
elif department_id:
|
||
|
dom.append(['department_id','=',department_id])
|
||
|
if view_type=='invoice':
|
||
|
field_names=['date','number','amount_due']
|
||
|
for inv in get_model('account.invoice').search_read(dom,field_names):
|
||
|
vals={}
|
||
|
for field_name in field_names:
|
||
|
vals[field_name]=inv[field_name],
|
||
|
lines.append(vals)
|
||
|
data={
|
||
|
'lines': lines,
|
||
|
'date_from': date_from,
|
||
|
'date_to': date_to,
|
||
|
'total_inv': len(lines),
|
||
|
'view_type': view_type,
|
||
|
}
|
||
|
return data
|
||
|
|
||
|
|
||
|
PaymentMatching.register()
|