Skip to content

Commit

Permalink
[ADD] datev_export_dtvf: Add example cronjob for periodic export
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed May 24, 2024
1 parent ff45d45 commit 9f2de7a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions datev_export_dtvf/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ To configure this module, you need to:
#. Fill in the fields in the `DATEV` tab
#. For accounts where you want to suppress automatic calculations (for ie taxes), set the according flag

The module also contains an inactive cronjob and a mail template allowing you to send period DATEV export somewhere via email. It relies on finding exactly one date range for the previous month and one for the year of the previous month, otherwise you'll see an error message in your log when running the cronjob. Note that the data transmitted via email is not encrypted.

Usage
=====

Expand Down
2 changes: 2 additions & 0 deletions datev_export_dtvf/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"datev_export",
],
"data": [
"data/ir_cron.xml",
"data/mail_template.xml",
"security/ir.model.access.csv",
"views/account_account.xml",
"views/datev_export_dtvf.xml",
Expand Down
34 changes: 34 additions & 0 deletions datev_export_dtvf/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<odoo noupdate="1">
<record id="cron_export" model="ir.cron">
<field name="name">Monthly DATEV export via mail (dtvf)</field>
<field name="interval_number">1</field>
<field name="interval_type">months</field>
<field name="numbercall">-1</field>
<field name="model_id" ref="model_datev_export_dtvf_export" />
<field name="active" eval="False" />
<field name="code">
<![CDATA[
relativedelta = dateutil.relativedelta.relativedelta
last_month_start = datetime.date.today() - relativedelta(months=1, day=1)
last_month_end = last_month_start + relativedelta(months=1, days=-1)
year_start = last_month_start + relativedelta(month=1, day=1)
year_end = year_start + relativedelta(years=1, days=-1)
year_range = env['date.range'].search([('date_start', '=', year_start), ('date_end', '=', year_end)], limit=1)
period_range = env['date.range'].search([('date_start', '=', last_month_start), ('date_end', '=', last_month_end)], limit=1)
if year_range and period_range:
export = model.create({
'fiscalyear_id': year_range.id,
'period_ids': [(6, 0, period_range.ids)],
'name': ('Export %s-%02d') % (last_month_start.year, last_month_start.month),
})
export.action_generate()
env.ref('datev_export_dtvf.mail_template_cron_export').send_mail(
export.id,
email_values={'attachments': [(export.file_name, export.file_data)]},
)
else:
raise UserError('No appropriate date ranges found for periodic export')
]]>
</field>
</record>
</odoo>
16 changes: 16 additions & 0 deletions datev_export_dtvf/data/mail_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<odoo noupdate="1">
<record id="mail_template_cron_export" model="mail.template">
<field name="name">DATEV export</field>
<field name="subject">{{object.name}}</field>
<field name="email_to">[email protected]</field>
<field name="model_id" ref="model_datev_export_dtvf_export" />
<field name="body_html" type="html">
<h1>Dear recipient,</h1>
<p>
please find attached the latest DATEV export from <t
t-out="object.company_id.name"
/>.
</p>
</field>
</record>
</odoo>
2 changes: 2 additions & 0 deletions datev_export_dtvf/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ To configure this module, you need to:
#. Go to your company
#. Fill in the fields in the `DATEV` tab
#. For accounts where you want to suppress automatic calculations (for ie taxes), set the according flag

The module also contains an inactive cronjob and a mail template allowing you to send period DATEV export somewhere via email. It relies on finding exactly one date range for the previous month and one for the year of the previous month, otherwise you'll see an error message in your log when running the cronjob. Note that the data transmitted via email is not encrypted.
1 change: 1 addition & 0 deletions datev_export_dtvf/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<li>Fill in the fields in the <cite>DATEV</cite> tab</li>
<li>For accounts where you want to suppress automatic calculations (for ie taxes), set the according flag</li>
</ol>
<p>The module also contains an inactive cronjob and a mail template allowing you to send period DATEV export somewhere via email. It relies on finding exactly one date range for the previous month and one for the year of the previous month, otherwise you’ll see an error message in your log when running the cronjob. Note that the data transmitted via email is not encrypted.</p>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
Expand Down

0 comments on commit 9f2de7a

Please sign in to comment.