Skip to content

Commit

Permalink
[IMP] l10n_it_fatturapa_in_purchase: black, isort, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
fredzamoabg committed Apr 22, 2021
1 parent 0eb8d53 commit 30e564c
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 72 deletions.
1 change: 0 additions & 1 deletion l10n_it_fatturapa_in_purchase/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

from . import models
20 changes: 9 additions & 11 deletions l10n_it_fatturapa_in_purchase/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@


{
'name': 'ITA - Fattura elettronica - Integrazione acquisti',
"name": "ITA - Fattura elettronica - Integrazione acquisti",
"summary": "Modulo ponte tra ricezione fatture elettroniche e acquisti",
'version': '12.0.1.0.2',
'category': 'Hidden',
'author': 'Agile Business Group, '
'Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/l10n-italy/tree/12.0/'
'l10n_it_fatturapa_in_purchase',
'license': 'AGPL-3',
"version": "12.0.1.0.2",
"category": "Hidden",
"author": "Agile Business Group, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-italy" "l10n_it_fatturapa_in_purchase",
"license": "AGPL-3",
"depends": [
'l10n_it_fatturapa_in',
'purchase',
"l10n_it_fatturapa_in",
"purchase",
],
"data": [
"views/invoice_view.xml",
],
"installable": True,
'auto_install': True,
"auto_install": True,
}
1 change: 0 additions & 1 deletion l10n_it_fatturapa_in_purchase/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

from . import purchase_order
31 changes: 19 additions & 12 deletions l10n_it_fatturapa_in_purchase/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,37 @@
# Copyright 2018 Sergio Zanchetta (Associazione PNLUG - Gruppo Odoo)
# Copyright 2019 Simone Rubino - Agile Business Group

from odoo import models, fields, api
from odoo import api, fields, models
from odoo.tools import float_compare


class POLine(models.Model):
_inherit = 'purchase.order.line'
to_invoice = fields.Boolean(
"To Invoice", compute="_compute_to_invoice", store=True)
_inherit = "purchase.order.line"
to_invoice = fields.Boolean("To Invoice", compute="_compute_to_invoice", store=True)

@api.depends(
"invoice_lines.invoice_id.state", "product_qty", "product_uom",
"invoice_lines.quantity", "invoice_lines.uom_id"
"invoice_lines.invoice_id.state",
"product_qty",
"product_uom",
"invoice_lines.quantity",
"invoice_lines.uom_id",
)
def _compute_to_invoice(self):
precision = self.env['decimal.precision'] \
.precision_get('Product Unit of Measure')
precision = self.env["decimal.precision"].precision_get(
"Product Unit of Measure"
)
for line in self:
if line.product_id.purchase_method == 'purchase':
if line.product_id.purchase_method == "purchase":
qty_to_invoice = line.product_qty
else:
qty_to_invoice = line.qty_received

if float_compare(line.qty_invoiced, qty_to_invoice,
precision_digits=precision) == -1:
if (
float_compare(
line.qty_invoiced, qty_to_invoice, precision_digits=precision
)
== -1
):
line.to_invoice = True
else:
line.to_invoice = False
Expand All @@ -34,6 +41,6 @@ def _compute_to_invoice(self):
def name_get(self):
res = []
for line in self:
name = "%s: %s" % (line.order_id.name, line.name)
name = "{}: {}".format(line.order_id.name, line.name)
res.append((line.id, name))
return res
19 changes: 12 additions & 7 deletions l10n_it_fatturapa_in_purchase/tests/data/IT05979361218_008.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<p:FatturaElettronica versione="FPA12" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:p="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2 http://www.fatturapa.gov.it/export/fatturazione/sdi/fatturapa/v1.2/Schema_del_file_xml_FatturaPA_versione_1.2.xsd">
<?xml version="1.0" encoding="UTF-8" ?>
<p:FatturaElettronica
versione="FPA12"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:p="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2 http://www.fatturapa.gov.it/export/fatturazione/sdi/fatturapa/v1.2/Schema_del_file_xml_FatturaPA_versione_1.2.xsd"
>
<FatturaElettronicaHeader>
<DatiTrasmissione>
<IdTrasmittente>
Expand Down Expand Up @@ -64,7 +67,8 @@ xsi:schemaLocation="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.
<Divisa>EUR</Divisa>
<Data>2015-06-22</Data>
<Numero>FT/2015/0012</Numero>
<Causale>Rif ordine MAPA: --- Nr. Identificativo Ordine 1234567</Causale>
<Causale
>Rif ordine MAPA: --- Nr. Identificativo Ordine 1234567</Causale>
</DatiGeneraliDocumento>
</DatiGenerali>
<DatiBeniServizi>
Expand All @@ -86,7 +90,8 @@ xsi:schemaLocation="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.
<Natura>N4</Natura>
<ImponibileImporto>9.00</ImponibileImporto>
<Imposta>0.00</Imposta>
<RiferimentoNormativo>Operazioni senza addebito imposta regime contribuenti minimi art.27 c.1-2 DL.98/11</RiferimentoNormativo>
<RiferimentoNormativo
>Operazioni senza addebito imposta regime contribuenti minimi art.27 c.1-2 DL.98/11</RiferimentoNormativo>
</DatiRiepilogo>
</DatiBeniServizi>
</FatturaElettronicaBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,45 @@

from datetime import datetime

from odoo.addons.l10n_it_fatturapa_in.tests.fatturapa_common import (
FatturapaCommon)
from odoo.fields import first
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT

from odoo.addons.l10n_it_fatturapa_in.tests.fatturapa_common import FatturapaCommon

class Testl10nItFatturapaInPurchase(FatturapaCommon):

class Testl10nItFatturapaInPurchase(FatturapaCommon):
def setUp(self):
super().setUp()
order_model = self.env['purchase.order']
self.partner_id = self.env.ref('base.res_partner_1')
self.product_id_1 = self.env.ref('product.product_product_8')
self.order = order_model.create({
'name': 'test_po',
'partner_id': self.partner_id.id,
'order_line': [
(0, 0, {
'name': self.product_id_1.name,
'product_id': self.product_id_1.id,
'product_qty': 5.0,
'product_uom': self.product_id_1.uom_po_id.id,
'price_unit': 500.0,
'date_planned': datetime.today().strftime(
DEFAULT_SERVER_DATETIME_FORMAT),
})]
})
order_model = self.env["purchase.order"]
self.partner_id = self.env.ref("base.res_partner_1")
self.product_id_1 = self.env.ref("product.product_product_8")
self.order = order_model.create(
{
"name": "test_po",
"partner_id": self.partner_id.id,
"order_line": [
(
0,
0,
{
"name": self.product_id_1.name,
"product_id": self.product_id_1.id,
"product_qty": 5.0,
"product_uom": self.product_id_1.uom_po_id.id,
"price_unit": 500.0,
"date_planned": datetime.today().strftime(
DEFAULT_SERVER_DATETIME_FORMAT
),
},
)
],
}
)

def test_to_invoice(self):
"""Check that `to_invoice` is computed correctly."""
res = self.run_wizard('test_to_invoice',
'IT05979361218_008.xml')
invoice_id = res.get('domain')[0][2][0]
res = self.run_wizard("test_to_invoice", "IT05979361218_008.xml")
invoice_id = res.get("domain")[0][2][0]
invoice = self.invoice_model.browse(invoice_id)

inv_line = first(invoice.invoice_line_ids)
Expand All @@ -46,13 +52,12 @@ def test_to_invoice(self):

def test_name_get(self):
"""Check that `name_get` works properly."""
res = self.run_wizard('test_name_get',
'IT05979361218_008.xml')
invoice_id = res.get('domain')[0][2][0]
res = self.run_wizard("test_name_get", "IT05979361218_008.xml")
invoice_id = res.get("domain")[0][2][0]
invoice = self.invoice_model.browse(invoice_id)

inv_line = first(invoice.invoice_line_ids)
order_line = first(self.order.order_line)
inv_line.purchase_line_id = order_line

self.assertEqual(order_line.display_name, 'test_po: Large Desk')
self.assertEqual(order_line.display_name, "test_po: Large Desk")
37 changes: 24 additions & 13 deletions l10n_it_fatturapa_in_purchase/views/invoice_view.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2018 Lorenzo Battistini
Copyright 2018 Sergio Zanchetta (Associazione PNLUG - Gruppo Odoo) -->
<odoo>

<record id="view_invoice_line_form_fatturapa_po_line" model="ir.ui.view">
<field name="name">view_invoice_line_form_fatturapa_po_line</field>
<field name="model">account.invoice.line</field>
<field name="inherit_id" ref="l10n_it_fatturapa.view_invoice_line_form_fatturapa"/>
<field
name="inherit_id"
ref="l10n_it_fatturapa.view_invoice_line_form_fatturapa"
/>
<field name="arch" type="xml">
<xpath expr="//div[@id='admin_ref']" position="after">
<group>
<field name="partner_id" invisible="1"/>
<field name="purchase_line_id"
attrs="{'invisible': [('fatturapa_attachment_in_id', '=', False)]}"
domain="[('partner_id', '=', partner_id), ('to_invoice', '=', True)]"
readonly="0" options="{'no_create': True}"
<field name="partner_id" invisible="1" />
<field
name="purchase_line_id"
attrs="{'invisible': [('fatturapa_attachment_in_id', '=', False)]}"
domain="[('partner_id', '=', partner_id), ('to_invoice', '=', True)]"
readonly="0"
options="{'no_create': True}"
/>
</group>
</xpath>
Expand All @@ -23,13 +28,19 @@
<record id="invoice_supplier_form_po_line" model="ir.ui.view">
<field name="name">invoice_supplier_form_po_line</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_supplier_form"/>
<field name="inherit_id" ref="account.invoice_supplier_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='analytic_tag_ids']" position="after">
<field name="partner_id" invisible="1"/>
<field name="purchase_line_id"
domain="[('partner_id', '=', partner_id), ('to_invoice', '=', True)]"
readonly="0" string="PO line" options="{'no_create': True}"
<xpath
expr="//field[@name='invoice_line_ids']/tree/field[@name='analytic_tag_ids']"
position="after"
>
<field name="partner_id" invisible="1" />
<field
name="purchase_line_id"
domain="[('partner_id', '=', partner_id), ('to_invoice', '=', True)]"
readonly="0"
string="PO line"
options="{'no_create': True}"
/>
</xpath>
</field>
Expand Down

0 comments on commit 30e564c

Please sign in to comment.