Skip to content
Snippets Groups Projects
Commit 69f4595c authored by Daniil Digtyar Vasilieva's avatar Daniil Digtyar Vasilieva :call_me:
Browse files

[IMP] energy_selfconsumption: add selfconsumption import template

parent de81efaa
No related branches found
No related tags found
2 merge requests!187Release 14.0.1.1.13,!155[IMP] energy_selfconsumption: importation of selfconsumption inscriptions, supply points and distribution tables by CSV
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data>
<record model="ir.attachment" id="selfconsumption_table_example_attachment">
<field name="name">import_selfconsumption_template.csv</field>
<field name="type">binary</field>
<field name="datas">
RE5JIFNvY2nDsyxGZWNoYSBlZmVjdGl2YSxDVVBTLENhbGxlIDEsQ2FsbDIsQ2l1ZGFkLEPDs2RpZ28gZGUgbGEgcHJvdmluY2lhLEPDs2RpZ28gcG9zdGFsLEPDs2RpZ28gSVNPIGRlbCBwYcOtcyxETkkgVGl0dWxhcixOb21icmUgVGl0dWxhcixBcGVsbGlkb3MgVGl0dWxhcgoyNDQ5NjUwOEosMDEvMDEvMjAyMyxFUzAzOTA3MjYyMDExNDkyNTNYTCxDYXJyZXIgTWFqb3IgMixOwrogMSxNYWRyaWQsTSwyODAwMSxFUywyNDQ5NjUwOEosLApZMjU4MzQyNkIsLEVTMDM5MDcwMDg3NjQ5NDUyMkpaLEF2ZW5pZGEgTWFqb3IsTsK6IDIsQmFyY2Vsb25hLEIsODAwMSxFUyxZMjU4MzQyNkIsLAowNTc0OTkxM00sLEVTMDM5MDg1ODQ3MTM2MDExM0JaLFRyYXZlc2lhIE1ham9yLE7CuiAyLExsZWlkYSxMLDI1MDAxLEVTLDA1NzQ5OTEzTSwsCg==
</field>
<field name="company_id"></field>
</record>
<record model="ir.attachment" id="distribution_table_example_attachment">
<field name="name">import_distribution_table_example.csv</field>
<field name="type">binary</field>
......
......@@ -37,9 +37,10 @@ class SelfconsumptionImportWizard(models.TransientModel):
@api.constrains("import_file")
def _constrains_import_file(self):
format = str(self.fname.split(".")[1])
if format != "csv":
raise ValidationError(_("Only csv format files are accepted."))
if self.fname:
format = str(self.fname.split(".")[1])
if format != 'csv':
raise ValidationError(_("Only csv format files are accepted."))
def import_file_button(self):
error_string_list = ""
......@@ -68,6 +69,15 @@ class SelfconsumptionImportWizard(models.TransientModel):
)
return True
def download_template_button(self):
distribution_table_example_attachment = self.env.ref('energy_selfconsumption.selfconsumption_table_example_attachment')
download_url = '/web/content/{}/?download=true'.format(str(distribution_table_example_attachment.id))
return {
"type": "ir.actions.act_url",
"url": download_url,
"target": "new",
}
def get_line_dict(self, line):
return {
"partner_vat": line[0] or False,
......
......@@ -8,6 +8,10 @@
<field name="arch" type="xml">
<form>
<sheet>
<p>You can download an example template for the import. The template must have this format and
be a CSV file.</p>
<button type="object" name="download_template_button">Download Template</button>
<separator/>
<group>
<field name="import_file" filename="fname" widget="binary"></field>
<field name="fname" invisible="1"></field>
......@@ -19,7 +23,7 @@
</group>
</sheet>
<footer>
<button type="object" name="import_file_button">IMPORT</button>
<button type="object" name="import_file_button">Import</button>
</footer>
</form>
</field>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment