การ Set Payment Term
โพสต์แล้ว: พุธ 01 เม.ย. 2015 11:51 am
ในกรณีที่ต้องการให้ตั้งการจ่ายเงินให้เป็น 50% แรกก่อนที่จะเริ่มทำงาน 7 วัน และ 50% หลังจากส่งมอบงานแล้ว มีวิธีการเซ็ตยังไงบ้างครับ
เว็บบอร์ด ส่งเสริม Software OpenSource ระบบ ERP ไปใช้งานในธุรกิจ แหล่งชุมนุมผู้ใช้ & พัฒนา Odoo/OpenERP โปรแกรมระบบ ERP ฟรี มาใช้งานในประเทศไทย ใช้ได้กับทุกประเภทธุรกิจ ใช้งานทั่วโลก!
https://www.openerpthailand.org/
โค้ด: เลือกทั้งหมด
class account_payment_term(osv.osv):
_inherit="account.payment.term"
def compute(self, cr, uid, id, value, date_ref=False, context=None):
if isinstance(id, list):
id = id[0]
if not date_ref:
date_ref = datetime.now().strftime('%Y-%m-%d')
pt = self.browse(cr, uid, id, context=context)
amount = value
result = []
prec = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')
for line in pt.line_ids:
if line.value == 'fixed':
amt = round(line.value_amount, prec)
elif line.value == 'procent':
amt = round(value * line.value_amount, prec)
elif line.value == 'balance':
amt = round(amount, prec)
elif line.value == 'division':
amt = round(value / line.value_amount, prec)
if amt:
next_date = datetime.strptime(date_ref, '%Y-%m-%d')
# Add months first
next_date += relativedelta(months=line.months or 0)
# Add days later
next_date += relativedelta(days=line.days)
if line.days2 < 0:
next_first_date = next_date + relativedelta(day=1,months=1) #Getting 1st of next month
next_date = next_first_date + relativedelta(days=line.days2)
if line.days2 > 0:
next_date += relativedelta(day=line.days2, months=1)
if line.exclude_month1 > 0:
if int(next_date.strftime('%m')) == line.exclude_month1:
next_date += relativedelta(months=1, day=line.exclude_day1)
if line.exclude_month2 > 0:
if int(next_date.strftime('%m')) == line.exclude_month2:
next_date += relativedelta(months=1, day=line.exclude_day2)
result.append( (next_date.strftime('%Y-%m-%d'), amt) )
amount -= amt
return result
account_payment_term()
class account_payment_term_line(osv.osv):
_inherit = 'account.payment.term.line'
_columns = {
'months': fields.integer('Number of Months', help="Number of months to add to invoice date."),
'exclude_month1': fields.integer('Trigger Month 1 ', help="First month to trigger the date."),
'exclude_day1': fields.integer('Day 1 Default', help="Day of the next Month to set."),
'exclude_month2': fields.integer('Trigger Month 2', help="Second month to trigger the date."),
'exclude_day2': fields.integer('Day 2 Default', help="Day of the next Month to set."),
'value': fields.selection([
('procent', 'Percent'),
('balance', 'Balance'),
('fixed', 'Fixed Amount'),
('division', 'Division'),
], 'Valuation', required=True, help="Select here the kind of valuation related to this payment term line. Note that you should have your last line with the type 'Balance' to ensure that the whole amount will be threated."),
'value_amount': fields.float('Value Amount', digits=(12,4), help="For Value percent enter % ratio between 0-1."),
}
account_payment_term_line()