โพสต์ โดย kitcle » เสาร์ 04 เม.ย. 2015 6:38 pm
ในการใช้ Payment Term Advanced ในระบบบัญชี
ต้องมีการ customize เพิ่มโดยการ ต่อเติมคลาส account.payment.term และ account.payment.term.line
เมื่อจัดการในส่วน Model เรียบร้อยแล้ว
ไว้ผมจะมาจัดการในส่วนของ Views เพื่อแสดงผลต่อนะครับ ^_^
โค้ด: เลือกทั้งหมด
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()
ในการใช้ Payment Term Advanced ในระบบบัญชี
ต้องมีการ customize เพิ่มโดยการ ต่อเติมคลาส account.payment.term และ account.payment.term.line
เมื่อจัดการในส่วน Model เรียบร้อยแล้ว
[b]ไว้ผมจะมาจัดการในส่วนของ Views เพื่อแสดงผลต่อนะครับ[/b] ^_^
[code]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()[/code]