Skip to content

Commit a0fa293

Browse files
[IMP] base_delivery_carrier_files: pass pickings to _write_file
_write_file was designed to be inheritable to implement other file storages, but without access to the pickings it is not possible to implement attachment or binary fields storage.
1 parent e074014 commit a0fa293

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

base_delivery_carrier_files/models/delivery_carrier_file.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_write_mode_selection(self):
2929
"""
3030
return [("disk", "Disk")]
3131

32-
def _write_file(self, filename, file_content):
32+
def _write_file(self, filename, file_content, pickings):
3333
"""
3434
Method responsible of writing the file, on the filesystem or
3535
by inheriting the module, in the document module as instance
@@ -38,6 +38,7 @@ def _write_file(self, filename, file_content):
3838
(configuration)
3939
:param tuple filename: name of the file to write
4040
:param tuple file_content: content of the file to write
41+
:param recordset pickings: pickings to which the file applies
4142
:return: True if write is successful
4243
"""
4344
for carrier_file in self:
@@ -75,20 +76,21 @@ def _generate_files(self, picking_ids):
7576

7677
for f in files:
7778
filename, file_content, picking_ids = f
79+
pickings = self.env["stock.picking"].browse(picking_ids or [])
7880
# we pass the errors because the files can still be
7981
# generated manually
8082
# at first I would like to open a new cursor and
8183
# commit the write after each file created
8284
# but I encountered lock because the picking
8385
# was already modified in the current transaction
8486
try:
85-
if this._write_file(filename, file_content):
87+
if this._write_file(filename, file_content, pickings):
8688
picking_obj.browse(picking_ids).write(
8789
{"carrier_file_generated": True}
8890
)
8991
except Exception as e:
9092
log.exception(
91-
"Could not create the picking file " "for pickings %s: %s",
93+
"Could not create the picking file for pickings %s: %s",
9294
picking_ids,
9395
e,
9496
)

base_delivery_carrier_files/tests/test_base_delivery_carrier_files.py

+2-14
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def setUp(self):
1919
"auto_export": True,
2020
"group_pickings": False,
2121
"write_mode": "disk",
22-
"export_path": "/tmp",
22+
"export_path": tempfile.gettempdir(),
2323
}
2424
)
2525

@@ -30,7 +30,7 @@ def setUp(self):
3030
"auto_export": False,
3131
"group_pickings": True,
3232
"write_mode": "disk",
33-
"export_path": "/tmp",
33+
"export_path": tempfile.gettempdir(),
3434
}
3535
)
3636

@@ -74,12 +74,6 @@ def setUp(self):
7474

7575
def test_carrier_file_generation(self):
7676
""" Test carrier file generation """
77-
# I configure the carrier file configuration
78-
# to write to the root document directory.
79-
self.carrier_file.write(
80-
{"export_path": tempfile.gettempdir(), "write_mode": "disk"}
81-
)
82-
8377
# I confirm outgoing shipment of 130 kgm Ice-cream.
8478
picking = self.env["stock.picking"].create(
8579
{
@@ -125,12 +119,6 @@ def test_carrier_file_generation(self):
125119

126120
def test_manual_carrier_file_generation(self):
127121
""" Test manual carrier file generation """
128-
# I configure the carrier file configuration
129-
# to write to the root document directory.
130-
self.carrier_file_manual.write(
131-
{"export_path": tempfile.gettempdir(), "write_mode": "disk"}
132-
)
133-
134122
# I confirm outgoing shipment of 130 kgm Ice-cream.
135123
picking = self.env["stock.picking"].create(
136124
{

0 commit comments

Comments
 (0)