Skip to content

Commit 9ba1d97

Browse files
committed
add required values
1 parent 59f6ff7 commit 9ba1d97

File tree

6 files changed

+73
-42
lines changed

6 files changed

+73
-42
lines changed

export_invoice_edi_auchan/models/account_move.py

+35-21
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
from odoo import fields, models
99

10+
from ..schema.base import SegmentInterfaceExc
1011
from ..schema.invoice_footer import PIESegment
1112
from ..schema.invoice_header import ENTSegment
1213
from ..schema.invoice_line import LIGSegment
1314
from ..schema.invoice_taxes import TVASegment
14-
from ..schema.partner import PARSegment
1515

1616
_logger = logging.getLogger()
1717

@@ -28,56 +28,70 @@ def _find_bl_info(self):
2828
"""Find entête "Numéro de BL" and date"""
2929
raise NotImplementedError
3030

31+
def _render_segment(self, segment, vals):
32+
try:
33+
res = segment(**vals).render()
34+
except SegmentInterfaceExc as e:
35+
self.env.context["export_auchan_errors"] += str(e)
36+
else:
37+
return res
38+
3139
def _prepare_export_data(self, idx):
3240
self.ensure_one()
3341
res = []
3442
source_orders = self.line_ids.sale_line_ids.order_id
3543
bl_nbr, bl_date = self._find_bl_info()
44+
self = self.with_context(export_auchan_errors="")
3645
# Segment Entete facture
3746
res.append(
38-
ENTSegment(
39-
**{
47+
self._render_segment(
48+
ENTSegment,
49+
{
4050
"invoice": self,
4151
"source_orders": source_orders,
4252
"bl_nbr": bl_nbr,
4353
"bl_date": bl_date,
44-
}
45-
).render()
54+
},
55+
)
4656
)
4757
# segment partner
4858
res.append(
49-
PARSegment(
50-
**{
59+
self._render_segment(
60+
ENTSegment,
61+
{
5162
"invoice": self,
52-
}
53-
).render()
63+
},
64+
)
5465
)
5566
# segment ligne de fatcure
5667
for idx, line in enumerate(self.invoice_line_ids, start=0):
5768
res.append(
58-
LIGSegment(
59-
**{
69+
self._render_segment(
70+
LIGSegment,
71+
{
6072
"line": line,
6173
"line_num": idx,
62-
}
63-
).render()
74+
},
75+
)
6476
)
6577
# Segment pied facture
6678
res.append(
67-
PIESegment(
68-
**{
79+
self._render_segment(
80+
PIESegment,
81+
{
6982
"invoice": self,
70-
}
71-
).render()
83+
},
84+
)
7285
)
7386
# segment ligne de TVA (détail des TVA)
7487
for tax_line in self.line_ids.filtered(lambda x: x.tax_line_id):
7588
res.append(
76-
TVASegment(
77-
**{
89+
self._render_segment(
90+
TVASegment,
91+
{
7892
"tax_line": tax_line,
79-
}
80-
).render()
93+
},
94+
)
8195
)
8296
# Segment END
8397
res.append("END")

export_invoice_edi_auchan/schema/base.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88
from odoo.tools import float_compare
99

1010

11+
class SegmentInterfaceExc(Exception):
12+
pass
13+
14+
1115
class SegmentInterface:
1216
def __init__(self, **kwargs):
1317
self.__dict__.update(kwargs)
1418

15-
def _format_values(self, size, value="", ctx=False):
19+
def _format_values(self, size, value="", required=True, ctx=False):
20+
if required and not value:
21+
raise ValueError()
1622
if not ctx:
1723
ctx = {}
1824
if not value:
@@ -49,9 +55,18 @@ def _format_values(self, size, value="", ctx=False):
4955

5056
def render(self):
5157
res = ""
52-
for fmt_data in self.get_values():
53-
fmt_val = self._format_values(*fmt_data)
54-
res += fmt_val + ";"
58+
errors = []
59+
for idx, fmt_data in enumerate(self.get_values(), start=1):
60+
try:
61+
fmt_val = self._format_values(*fmt_data)
62+
res += fmt_val + ";"
63+
except ValueError:
64+
errors += [(self.__name__, idx)]
65+
if errors:
66+
errstr = ""
67+
for el in errors:
68+
errstr += f"Segment {el[0]}: missing value on line {el[1]}\n"
69+
raise SegmentInterfaceExc(errstr)
5570
return res[:-1]
5671

5772
def get_values(self):

export_invoice_edi_auchan/schema/invoice_header.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def get_values(self):
1414
10,
1515
self.source_orders and self.source_orders[0].date_order or "",
1616
), # Date de commande JJ/MM/AAAA
17-
(5, ""), # Heure de commande HH:MN opt
18-
(10, ""), # date du message opt
19-
(5, ""), # Heure du message opt
17+
(5, "", False), # Heure de commande HH:MN opt
18+
(10, "", False), # date du message opt
19+
(5, "", False), # Heure du message opt
2020
(
2121
10,
2222
self.bl_date,
@@ -25,10 +25,10 @@ def get_values(self):
2525
35,
2626
self.bl_nbr,
2727
), # num du BL JJ/MM/AAAA
28-
(10, ""), # Date avis d'expédition JJ/MM/AAAA opt
29-
(35, ""), # Numéro de l'avis d'expédition opt
30-
(10, ""), # Date d'enlèvement JJ/MM/AAAA opt
31-
(5, ""), # Heure d'enlèvement HH:MN opt
28+
(10, "", False), # Date avis d'expédition JJ/MM/AAAA opt
29+
(35, "", False), # Numéro de l'avis d'expédition opt
30+
(10, "", False), # Date d'enlèvement JJ/MM/AAAA opt
31+
(5, "", False), # Heure d'enlèvement HH:MN opt
3232
(35, self.invoice.name), # Numéro de document
3333
(
3434
16,
@@ -44,17 +44,22 @@ def get_values(self):
4444
), # Type de document (Facture/Avoir)
4545
# depend on 'move_type', 'in', ('out_invoice', 'out_refund')
4646
(3, self.invoice.currency_id.name), # Code monnaie (EUR pour Euro)
47-
(10, ""), # Date d'échéance pour l'escompte JJ/MM/AAAA opt
47+
(10, "", False), # Date d'échéance pour l'escompte JJ/MM/AAAA opt
4848
(
4949
10,
5050
"",
51+
False,
5152
), # Montant de l'escompte (le pourcentage de l'escompte est préconisé) opt
52-
(35, ""), # Numéro de facture en référence (obligatoire si avoir) opt
53-
(10, ""), # Date de facture en référence (obligatoire si avoir) opt
54-
(6, ""), # Pourcentage de l'escompte opt
55-
(3, ""), # Nb de jour de l'escompte opt
56-
(6, ""), # Pourcentage de pénalité opt
57-
(3, ""), # Nb de jour de pénalité opt
53+
(
54+
35,
55+
"",
56+
False,
57+
), # Numéro de facture en référence (obligatoire si avoir) opt
58+
(10, "", False), # Date de facture en référence (obligatoire si avoir) opt
59+
(6, "", False), # Pourcentage de l'escompte opt
60+
(3, "", False), # Nb de jour de l'escompte opt
61+
(6, "", False), # Pourcentage de pénalité opt
62+
(3, "", False), # Nb de jour de pénalité opt
5863
(
5964
1,
6065
self.invoice.env.context.get("test_mode") and "1" or "0",

export_invoice_edi_auchan/schema/invoice_line.py

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class LIGSegment(SegmentInterface):
99
def get_values(self):
10-
1110
uom = (
1211
self.line.product_uom_id.name == "kg"
1312
and "KGM"

export_invoice_edi_auchan/schema/invoice_taxes.py

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class TVASegment(SegmentInterface):
99
def get_values(self):
10-
1110
return [
1211
(3, "TVA"), # Étiquette de segment "TVA"
1312
(5, self.tax_line.tax_line_id.amount or 0.0),

export_invoice_edi_auchan/schema/partner.py

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
class PARSegment(SegmentInterface):
99
def get_values(self):
10-
1110
return [
1211
(3, "PAR"),
1312
(13, self.invoice.partner_id.barcode), # Code EAN client

0 commit comments

Comments
 (0)