diff --git a/aeat347.txt b/aeat347.txt
new file mode 100644
index 0000000000..f031933a47
--- /dev/null
+++ b/aeat347.txt
@@ -0,0 +1,4 @@
+1347${year}${company.party.tax_identifier.code[2:]}${justify(company.rec_name.upper(), 40)}T000000000${justify('', 40)}347${year}000001${justify('', 15)}${format_integer(len(records), 9)}${format_decimal(records_amount)}${format_integer(0, 9)}${format_decimal(0)}${justify('', 315)}
+{% for record in records %}\
+2347${year}${justify(identifier_code(record.company_tax_identifier), 9)}${justify(identifier_code(record.party_tax_identifier), 9)}${justify('', 9)}${justify(strip_accents(record.party.name.upper()), 40)}D${justify(record.province_code, 2)}${justify(country_code(record), 2)} ${record.code}${format_decimal(record.amount)} 000000000000000${format_decimal(0)}0000${format_decimal(record.first_period_amount or 0)}${format_decimal(0)}${format_decimal(record.second_period_amount or 0)}${format_decimal(0)}${format_decimal(record.third_period_amount or 0)}${format_decimal(0)}${format_decimal(record.fourth_period_amount or 0)}${format_decimal(0)}${justify('', 20)}${format_decimal(0)}${justify('', 201)}
+{% end %}\
diff --git a/aeat349.txt b/aeat349.txt
new file mode 100644
index 0000000000..ae23e30d32
--- /dev/null
+++ b/aeat349.txt
@@ -0,0 +1,4 @@
+1349${year}${company.party.tax_identifier.code[2:]}${justify(company.rec_name.upper(), 40)}T000000000${justify('', 40)}349${year}${period_number}0001 0000000000000${period}${format_integer(len(records), 9)}${format_decimal(records_amount, 15)}${format_integer(0, 9)}${format_decimal(0), 15}${justify('', 315)}
+{% for record in records %}\
+2349${year}${justify(identifier_code(record.company_tax_identifier), 9)}${justify('', 58)}${justify(record.party_tax_identifier.code if record.party_tax_identifier else '', 17)}${justify(record.party.name.upper(), 40)}${record.code}${format_decimal(record.amount)}${justify('', 354)}
+{% end %}\
diff --git a/party.py b/party.py
new file mode 100644
index 0000000000..7a54db6c12
--- /dev/null
+++ b/party.py
@@ -0,0 +1,23 @@
+# This file is part of Tryton. The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+from trytond.model import fields
+from trytond.pool import PoolMeta
+
+__all__ = ['Party']
+
+
+class Party(metaclass=PoolMeta):
+ __name__ = 'party.party'
+
+ es_province_code = fields.Char("Spanish Province Code", size=2,
+ help="Set 99 for non Spanish parties.")
+
+ @fields.depends('addresses', 'es_province_code')
+ def on_change_addresses(self):
+ if not self.es_province_code:
+ for address in self.addresses:
+ country = getattr(address, 'country', None)
+ zip_ = getattr(address, 'zip', None)
+ if country and zip_ and country.code == 'ES':
+ self.es_province_code = zip_[:2]
+ break
diff --git a/party.xml b/party.xml
new file mode 100644
index 0000000000..e5c6732c93
--- /dev/null
+++ b/party.xml
@@ -0,0 +1,12 @@
+
+
+