Skip to content

Commit

Permalink
[IMP]l10n_it_ddt : Extend the fatturapa xml invoice and make a
Browse files Browse the repository at this point in the history
link with the ddt.

task-id:1914640
  • Loading branch information
anr-odoo committed Sep 23, 2019
1 parent 0828f36 commit 0c131e1
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 12 deletions.
8 changes: 4 additions & 4 deletions addons/l10n_it_ddt/__manifest__.py
Expand Up @@ -4,11 +4,11 @@
'website': 'https://www.odoo.com',
'category': 'Localization',
'version': '0.1',

'depends': ['l10n_it', 'sale_stock', 'delivery'],

'depends': ['l10n_it_edi', 'sale_stock', 'delivery'],
'data': [
'report/l10n_it_ddt_report.xml',
'views/stock_picking_views.xml',
]
'data/l10n_it_ddt_template.xml',
],
'auto_install': True,
}
21 changes: 21 additions & 0 deletions addons/l10n_it_ddt/data/l10n_it_ddt_template.xml
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<template id="my_view_name" inherit_id="l10n_it_edi.account_invoice_it_FatturaPA_export">
<xpath expr='//DatiDDT' position="after">
<t t-if="ddt_dict">
<t t-set="picking_count" t-value="1"/>
<t t-foreach="ddt_dict" t-as="picking">
<DatiDDT>
<NumeroDDT t-esc="picking.name"/>
<DataDDT t-esc="format_date(picking.date)"/>
<t t-esc="picking_count"/>
<t t-if="len(ddt_dict) > 1">
<RiferimentoNumeroLinea t-esc="picking_count"/>
</t>
<t t-set="picking_count" t-value ="1 + picking_count"/>
</DatiDDT>
</t>
</t>
</xpath>
</template>
</odoo>
1 change: 1 addition & 0 deletions addons/l10n_it_ddt/models/__init__.py
Expand Up @@ -2,3 +2,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import stock_picking
from . import account_invoice
39 changes: 39 additions & 0 deletions addons/l10n_it_ddt/models/account_invoice.py
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models


class AccountInvoice(models.Model):
_inherit = 'account.move'

def _get_ddt_values(self):
res = {}
for line in self.invoice_line_ids.filtered(lambda l: not l.display_type):
sale_order = line.sale_line_ids.mapped('order_id')
invoice = sale_order.invoice_ids.filtered(lambda x: x.invoice_date)
all_inv_qty = {}
for invoice_line in invoice.mapped('invoice_line_ids').filtered(lambda x: x.product_id == line.product_id):
all_inv_qty.setdefault(invoice_line, 0)
all_inv_qty[invoice_line] += invoice_line.quantity
picking_moves = sale_order.order_line.mapped('move_ids').filtered(lambda x: x.picking_id.date_done and line.product_id in x.mapped('product_id'))
invoice_line_related_pickings = {}
for picking_move in picking_moves.sorted(key=lambda x: x.picking_id.date_done, reverse=True):
qty = picking_move.quantity_done
for invoice_line, invoice_qty in all_inv_qty.items():
qty -= invoice_qty
if qty < 0 and not invoice_line_related_pickings:
break
else:
invoice_line_related_pickings.setdefault(invoice_line, {})
invoice_line_related_pickings[invoice_line].update({picking_move.picking_id: []})
picking_move.picking_id.invoice_ids += line.move_id
if qty <= 0:
break
res.update(invoice_line_related_pickings.get(line, {}))
return res

def _export_as_xml(self, template_values):
template_values['ddt_dict'] = self._get_ddt_values()
content = self.env.ref('l10n_it_edi.account_invoice_it_FatturaPA_export').render(template_values)
return content
23 changes: 20 additions & 3 deletions addons/l10n_it_ddt/models/stock_picking.py
Expand Up @@ -9,6 +9,23 @@ class StockPicking(models.Model):

l10n_it_transport_reason_id = fields.Selection([('sale', 'Sale'), ('repair', 'Repair')], string='Transport Reason')
l10n_it_transport_method_id = fields.Selection([('sender', 'Sender'), ('recipient', 'Recipient'), ('courier', 'Courier service')], string='Transport Reason')
l10n_it_parcels = fields.Integer(string="parcels")
l10n_it_volume = fields.Integer(string="volume")
l10n_it_size = fields.Text(string="size")
l10n_it_parcels = fields.Integer(string="Parcels")
l10n_it_volume = fields.Integer(string="Volume")
l10n_it_size = fields.Text(string="Size")
invoice_ids = fields.Many2many('account.move', string="Invoices")

def report_name(self):
for picking in self:
a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
n = picking.id
progressive_number = ""
while n:
(n, m) = divmod(n, len(a))
progressive_number = a[m] + progressive_number

report_name = '%(country_code)s%(codice)s_%(progressive_number)s.xml' % {
'country_code': picking.company_id.country_id.code,
'codice': picking.company_id.l10n_it_codice_fiscale,
'progressive_number': progressive_number.zfill(5),
}
return report_name
9 changes: 7 additions & 2 deletions addons/l10n_it_ddt/report/l10n_it_ddt_report.xml
Expand Up @@ -21,7 +21,12 @@
</div>
</div>
<div class="mt16"/>
<div></div>
<div class="mt16"/>
<div>
<t t-foreach="o.invoice_ids.mapped('l10n_it_ddt_id')" t-as="ddt_id">
<h1 t-esc="ddt_id.name"/>
</t>
</div>
<div class="clearfix"/>
<div class="mb32"/>
<table class="table table-bordered">
Expand Down Expand Up @@ -165,6 +170,6 @@
report_type="qweb-pdf"
name="l10n_it_ddt.report_ddt_view"
file="report_ddt"
print_report_name="'DDT'"
print_report_name="(object.report_name())"
/>
</odoo>
2 changes: 1 addition & 1 deletion addons/l10n_it_ddt/views/stock_picking_views.xml
Expand Up @@ -9,7 +9,7 @@
<field name="l10n_it_transport_reason_id" string="Transport Reason"/>
<field name="l10n_it_transport_method_id" string="Transport Method"/>
<field name="l10n_it_volume" string="Volume"/>
<field name="l10n_it_parcels" string="parcels"/>
<field name="l10n_it_parcels" string="Parcels"/>
<field name="l10n_it_size" string="Size"/>
</xpath>
</field>
Expand Down
8 changes: 6 additions & 2 deletions addons/l10n_it_edi/models/account_invoice.py
Expand Up @@ -154,7 +154,7 @@ def invoice_generate_xml(self):
}
invoice.l10n_it_einvoice_name = report_name

data = b"<?xml version='1.0' encoding='UTF-8'?>" + invoice._export_as_xml()
data = b"<?xml version='1.0' encoding='UTF-8'?>" + invoice._get_export_values()
description = _('Italian invoice: %s') % invoice.type
invoice.l10n_it_einvoice_id = self.env['ir.attachment'].create({
'name': report_name,
Expand All @@ -169,7 +169,7 @@ def invoice_generate_xml(self):
body=(_("E-Invoice is generated on %s by %s") % (fields.Datetime.now(), self.env.user.display_name))
)

def _export_as_xml(self):
def _get_export_values(self):
''' Create the xml file content.
:return: The XML content as str.
'''
Expand Down Expand Up @@ -248,6 +248,10 @@ def get_vat_country(vat):
'pdf': pdf,
'pdf_name': pdf_name,
}
content = self._export_as_xml(template_values)
return content

def _export_as_xml(self, template_values):
content = self.env.ref('l10n_it_edi.account_invoice_it_FatturaPA_export').render(template_values)
return content

Expand Down

0 comments on commit 0c131e1

Please sign in to comment.