任何人都可以帮我在date_due过后自动为开放发票添加费用吗?例如,我在res.company中设置管理费,当发票到期时调用。
此致 乔
答案 0 :(得分:1)
如果您想自动添加,请添加scheduler
。计划程序功能应在截止日期之后搜索所有未结发票,并添加带有管理费的新发票行或将管理费添加到现有发票行。
例如,下面是可用于创建调度程序的数据xml。
XML部分
<record forcecreate="True" id="ir_cron_auto_invoice_scheduler_action" model="ir.cron">
<field name="name">Run Automatic Invoice scheduler</field>
<field eval="True" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field eval="True" name="doall"/>
<field eval="'your.model.name'" name="model"/><!--here it is account.invoice-->
<field eval="'automatic_invoice_scheduler'" name="function"/>
<!--its a new function in account.invoice model-->
<!-- from which you can search all the invoices and what you need-->
<field eval="'(False,)'" name="args"/>
</record>
Python部分
#Its just a example function.make necessary changes
#Inherit the account_invoice and add the function
import time
def automatic_invoice_scheduler(self, cr, uid, ids,context=None):
ids = self.search(cr, uid,[('date_invoice','<=',time.strftime('%Y-%m-%d %H:%M:%S'),('state','open'),('due_added','=',False)], context=context)
#due added is a new field you have to add so that once the due
# is added then its invoice id is not added in the scheduler
###########################
#Add your code here.add the due_fees to the invoice lines
#write the due_added boolean field to true
###########################
return True