diff --git a/base_delivery_carrier_files_document/README.rst b/base_delivery_carrier_files_document/README.rst new file mode 100644 index 0000000000..21cd7854d5 --- /dev/null +++ b/base_delivery_carrier_files_document/README.rst @@ -0,0 +1,21 @@ +**This file is going to be generated by oca-gen-addon-readme.** + +*Manual changes will be overwritten.* + +Please provide content in the ``readme`` directory: + +* **DESCRIPTION.rst** (required) +* INSTALL.rst (optional) +* CONFIGURE.rst (optional) +* **USAGE.rst** (optional, highly recommended) +* DEVELOP.rst (optional) +* ROADMAP.rst (optional) +* HISTORY.rst (optional, recommended) +* **CONTRIBUTORS.rst** (optional, highly recommended) +* CREDITS.rst (optional) + +Content of this README will also be drawn from the addon manifest, +from keys such as name, authors, maintainers, development_status, +and license. + +A good, one sentence summary in the manifest is also highly recommended. diff --git a/base_delivery_carrier_files_document/__init__.py b/base_delivery_carrier_files_document/__init__.py index a9efa239a5..25f9e3b361 100644 --- a/base_delivery_carrier_files_document/__init__.py +++ b/base_delivery_carrier_files_document/__init__.py @@ -1,22 +1,6 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Author: Guewen Baconnier -# Copyright 2012 Camptocamp SA -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# Copyright 2012 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from . import carrier_file # noqa +from . import models +from . import tests diff --git a/base_delivery_carrier_files_document/__manifest__.py b/base_delivery_carrier_files_document/__manifest__.py index 67ff2bcef5..e0c147bb0b 100644 --- a/base_delivery_carrier_files_document/__manifest__.py +++ b/base_delivery_carrier_files_document/__manifest__.py @@ -1,43 +1,25 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Author: Guewen Baconnier -# Copyright 2012 Camptocamp SA -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - +# Copyright 2012 Camptocamp SA +# Author: Guewen Baconnier +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Base module for picking carrier files creation for document', - 'version': '1.0.1', + 'version': '8.0.1.0.1', 'category': 'Generic Modules/Warehouse', - 'description': """ -Allow to store the carrier files in a Document directory. -Auto-install when the module Document and -Base Delivery Carrier Files are installed. - """, - 'author': "Camptocamp,Odoo Community Association (OCA)", + 'author': 'Camptocamp,Odoo Community Association (OCA)', 'license': 'AGPL-3', 'website': 'http://www.camptocamp.com', - 'depends': ['base_delivery_carrier_files', - 'document'], - 'data': ['carrier_file_view.xml'], - 'demo': ['carrier_file_demo.xml'], - 'test': ['test/carrier_file.yml', - 'test/carrier_file_manual.yml'], + 'depends': [ + 'base_delivery_carrier_files', + 'document' + ], + 'data': [ + 'views/carrier_file_view.xml' + ], + 'demo': [ + 'demo/carrier_file_demo.xml' + ], 'images': [], - 'installable': False, + 'installable': True, 'auto_install': True, } diff --git a/base_delivery_carrier_files_document/carrier_file.py b/base_delivery_carrier_files_document/carrier_file.py deleted file mode 100644 index f228dded9a..0000000000 --- a/base_delivery_carrier_files_document/carrier_file.py +++ /dev/null @@ -1,72 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Author: Guewen Baconnier -# Copyright 2012 Camptocamp SA -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -import base64 - -from openerp.osv import orm, fields - - -class CarrierFile(orm.Model): - _inherit = 'delivery.carrier.file' - - def get_write_mode_selection(self, cr, uid, context=None): - res = super(CarrierFile, self).\ - get_write_mode_selection(cr, uid, context=context) - if 'document' not in res: - res.append(('document', 'Document')) - return res - - _columns = { - 'write_mode': fields.selection(get_write_mode_selection, 'Write on', - required=True), - 'document_directory_id': fields.many2one('document.directory', - 'Document Directory'), - 'export_path': fields.char('Export Path', size=256), - } - - def _prepare_attachment(self, carrier_file, filename, file_content, - context): - if carrier_file.auto_export: - assert context is not None and 'picking_id' in context, \ - ('When carrier_file is in mode auto_export, picking_id must ' - 'be in context') - res_id = context['picking_id'] - else: - res_id = False - return {'name': "%s_%s" % (carrier_file.name, filename), - 'datas_fname': filename, - 'datas': base64.encodestring(file_content), - 'parent_id': carrier_file.document_directory_id.id, - 'type': 'binary', - 'res_model': 'stock.picking.out', - 'res_id': res_id} - - def _write_file(self, cr, uid, carrier_file, filename, file_content, - context=None): - if carrier_file.write_mode == 'document': - vals = self._prepare_attachment(carrier_file, filename, - file_content, context=context) - self.pool['ir.attachment'].create(cr, uid, vals, context=context) - return True - else: - return (super(CarrierFile, self) - ._write_file(cr, uid, carrier_file, filename, file_content, - context=context)) diff --git a/base_delivery_carrier_files_document/carrier_file_demo.xml b/base_delivery_carrier_files_document/demo/carrier_file_demo.xml similarity index 100% rename from base_delivery_carrier_files_document/carrier_file_demo.xml rename to base_delivery_carrier_files_document/demo/carrier_file_demo.xml diff --git a/base_delivery_carrier_files_document/models/__init__.py b/base_delivery_carrier_files_document/models/__init__.py new file mode 100644 index 0000000000..4d482fb302 --- /dev/null +++ b/base_delivery_carrier_files_document/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2012 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import delivery_carrier_file diff --git a/base_delivery_carrier_files_document/models/delivery_carrier_file.py b/base_delivery_carrier_files_document/models/delivery_carrier_file.py new file mode 100644 index 0000000000..92c78cbf5c --- /dev/null +++ b/base_delivery_carrier_files_document/models/delivery_carrier_file.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2012 Camptocamp SA +# Author: Guewen Baconnier +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import base64 + +from openerp import api, models, fields + + +class DeliveryCarrierFile(models.Model): + _inherit = 'delivery.carrier.file' + + @api.model + def get_write_mode_selection(self): + res = super(DeliveryCarrierFile, self).get_write_mode_selection() + if 'document' not in [a[0] for a in res]: + res.append(('document', 'Document')) + return res + + document_directory_id = fields.Many2one('document.directory') + + @api.model + def _prepare_attachment(self, carrier_file, filename, file_content): + return {'name': "%s_%s" % (carrier_file.name, filename), + 'datas_fname': filename, + 'datas': base64.encodestring(file_content), + 'parent_id': carrier_file.document_directory_id.id, + 'type': 'binary'} + + @api.multi + def _write_file(self, filename, file_content): + ret = True + for this in self: + if this.write_mode == 'document': + vals = self._prepare_attachment( + this, filename, file_content) + self.env['ir.attachment'].create(vals) + ret &= True + else: + ret &= super(DeliveryCarrierFile, this)._write_file( + filename, file_content) + return ret diff --git a/base_delivery_carrier_files_document/readme/CONTRIBUTORS.rst b/base_delivery_carrier_files_document/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..04c8d2531c --- /dev/null +++ b/base_delivery_carrier_files_document/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Guewen Baconnier +* Tom Blauwendraat diff --git a/base_delivery_carrier_files_document/readme/DESCRIPTION.rst b/base_delivery_carrier_files_document/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..25f9f8757b --- /dev/null +++ b/base_delivery_carrier_files_document/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +Allows to store the delivery carrier files in a Document directory. +Auto-installs when the module Document and Base Delivery Carrier Files are installed. + diff --git a/base_delivery_carrier_files_document/test/carrier_file.yml b/base_delivery_carrier_files_document/test/carrier_file.yml deleted file mode 100644 index 31e3f6f2ef..0000000000 --- a/base_delivery_carrier_files_document/test/carrier_file.yml +++ /dev/null @@ -1,40 +0,0 @@ -- - In order to test Carrier file generation in a document directory -- - I set the system tempfile on the carrier file configuration to be sure the path will be writable -- - !python {model: delivery.carrier.file}: | - import tempfile - delivery_carrier_file = self.browse(cr, uid, ref("base_delivery_carrier_files.delivery_carrier_file")) - self.write(cr, uid, delivery_carrier_file.id, {'document_directory_id': ref('document.dir_root'), 'write_mode': 'document'}) -- - I set the carrier file configuration on the carrier Free delivery charges -- - !record {model: delivery.carrier, id: delivery.delivery_carrier}: - carrier_file_id: base_delivery_carrier_files.delivery_carrier_file -- - I confirm outgoing shipment of 130 kgm Ice-cream. -- - !workflow {model: stock.picking, action: button_confirm, ref: base_delivery_carrier_files.outgoing_shipment_carrier_file} -- - I check outgoing shipment after stock availablity in refrigerator. -- - !python {model: stock.picking}: | - self.force_assign(cr, uid, [ref("base_delivery_carrier_files.outgoing_shipment_carrier_file")]) - picking = self.browse(cr, uid, ref("base_delivery_carrier_files.outgoing_shipment_carrier_file")) -- - I deliver outgoing shipment. -- - !python {model: stock.partial.picking}: | - context.update({'active_model': 'stock.picking.out', 'active_id': ref('base_delivery_carrier_files.outgoing_shipment_carrier_file'), 'active_ids': [ref('base_delivery_carrier_files.outgoing_shipment_carrier_file')]}) -- - !record {model: stock.partial.picking, id: partial_outgoing}: - picking_id: base_delivery_carrier_files.outgoing_shipment_carrier_file -- - !python {model: stock.partial.picking }: | - self.do_partial(cr, uid, [ref('partial_outgoing')], context=context) -- - I check shipment details after shipment, the carrier file must have been generated -- - !assert {model: stock.picking.out, id: base_delivery_carrier_files.outgoing_shipment_carrier_file, string: Carrier file should be generated}: - - carrier_file_generated == True diff --git a/base_delivery_carrier_files_document/test/carrier_file_manual.yml b/base_delivery_carrier_files_document/test/carrier_file_manual.yml deleted file mode 100644 index e3b15f36a1..0000000000 --- a/base_delivery_carrier_files_document/test/carrier_file_manual.yml +++ /dev/null @@ -1,51 +0,0 @@ -- - In order to test Carrier file generation in a document directory -- - I set the system tempfile on the carrier file configuration to be sure the path will be writable -- - !python {model: delivery.carrier.file}: | - import tempfile - delivery_carrier_file = self.browse(cr, uid, ref("base_delivery_carrier_files.delivery_carrier_file_manual")) - self.write(cr, uid, delivery_carrier_file.id, {'document_directory_id': ref('document.dir_root'), 'write_mode': 'document'}) -- - I set the carrier file configuration on the carrier Free delivery charges -- - !record {model: delivery.carrier, id: delivery.free_delivery_carrier}: - carrier_file_id: base_delivery_carrier_files.delivery_carrier_file_manual -- - I confirm outgoing shipment of 130 kgm Ice-cream. -- - !workflow {model: stock.picking, action: button_confirm, ref: base_delivery_carrier_files.outgoing_shipment_carrier_file_manual} -- - I check outgoing shipment after stock availablity in refrigerator. -- - !python {model: stock.picking}: | - self.force_assign(cr, uid, [ref("base_delivery_carrier_files.outgoing_shipment_carrier_file_manual")]) - picking = self.browse(cr, uid, ref("base_delivery_carrier_files.outgoing_shipment_carrier_file_manual")) -- - I deliver outgoing shipment. -- - !python {model: stock.partial.picking}: | - context.update({'active_model': 'stock.picking.out', 'active_id': ref('base_delivery_carrier_files.outgoing_shipment_carrier_file_manual'), 'active_ids': [ref('base_delivery_carrier_files.outgoing_shipment_carrier_file_manual')]}) -- - !record {model: stock.partial.picking, id: partial_outgoing}: - picking_id: base_delivery_carrier_files.outgoing_shipment_carrier_file_manual -- - !python {model: stock.partial.picking }: | - self.do_partial(cr, uid, [ref('partial_outgoing')], context=context) -- - I check shipment details after shipment, the carrier file must not have been generated -- - !assert {model: stock.picking.out, id: base_delivery_carrier_files.outgoing_shipment_carrier_file_manual, string: Carrier file should be generated}: - - carrier_file_generated is False -- - I generate the carrier files of my shipment from the wizard -- - !python {model: delivery.carrier.file.generate}: | - wizard_id = self.create(cr, uid, {}, {'active_ids': [ref('base_delivery_carrier_files.outgoing_shipment_carrier_file_manual')], 'active_model': 'stock.picking.out'}) - self.action_generate(cr, uid, [wizard_id], {'active_ids': [ref('base_delivery_carrier_files.outgoing_shipment_carrier_file_manual')]}) -- - I check shipment details after manual generation, the carrier file must have been generated -- - !assert {model: stock.picking.out, id: base_delivery_carrier_files.outgoing_shipment_carrier_file_manual, string: Carrier file should be generated}: - - carrier_file_generated == True diff --git a/base_delivery_carrier_files_document/tests/__init__.py b/base_delivery_carrier_files_document/tests/__init__.py new file mode 100644 index 0000000000..47d7977674 --- /dev/null +++ b/base_delivery_carrier_files_document/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2012 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_base_delivery_carrier_files_document diff --git a/base_delivery_carrier_files_document/tests/test_base_delivery_carrier_files_document.py b/base_delivery_carrier_files_document/tests/test_base_delivery_carrier_files_document.py new file mode 100644 index 0000000000..d88f243af9 --- /dev/null +++ b/base_delivery_carrier_files_document/tests/test_base_delivery_carrier_files_document.py @@ -0,0 +1,102 @@ +# -*- coding: utf-8 -*- +# Copyright 2012 Guewen Baconnier +# Copyright 2018 Sunflower IT (http://sunflowerweb.nl) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.tests.common import TransactionCase + + +class CarrierFilesDocumentTest(TransactionCase): + + def test_carrier_file_generation(self): + """ Test carrier file generation """ + # I set the system tempfile on the carrier file configuration + # to be sure the path will be writable + carrier_file = self.env.ref( + 'base_delivery_carrier_files.delivery_carrier_file') + carrier_file.write({ + 'document_directory_id': self.env.ref('document.dir_root').id, + 'write_mode': 'document' + }) + + # I set the carrier file configuration on the carrier + # 'Free delivery charges' + carrier = self.env.ref('delivery.delivery_carrier') + carrier.carrier_file_id = carrier_file.id + + # I confirm outgoing shipment of 130 kgm Ice-cream. + picking = self.env.ref( + 'base_delivery_carrier_files.outgoing_shipment_carrier_file') + picking.action_confirm() + + # I check outgoing shipment after stock availablity in refrigerator. + picking.force_assign() + + # I deliver outgoing shipment. + wizard = self.env['stock.transfer_details'].with_context({ + 'active_model': 'stock.picking', + 'active_id': picking.id, + 'active_ids': picking.ids + }).create({ + 'picking_id': picking.id + }) + wizard.do_detailed_transfer() + + # I check shipment details after shipment + # The carrier file must have been generated. + self.assertTrue(picking.carrier_file_generated) + + # I check outgoing shipment copy + # The carrier_file_generated field must be unchecked. + new_picking = picking.copy() + self.assertFalse(new_picking.carrier_file_generated) + + def test_manual_carrier_file_generation(self): + """ Test manual carrier file generation """ + # I set the system tempfile on the carrier file configuration + # to be sure the path will be writable + carrier_file = self.env.ref( + 'base_delivery_carrier_files.delivery_carrier_file_manual') + carrier_file.write({ + 'document_directory_id': self.env.ref('document.dir_root').id, + 'write_mode': 'document' + }) + + # I set the carrier file configuration on the carrier + # 'Free delivery charges' + carrier = self.env.ref('delivery.delivery_carrier') + carrier.carrier_file_id = carrier_file.id + + # I confirm outgoing shipment of 130 kgm Ice-cream. + picking = self.env.ref( + 'base_delivery_carrier_files' + '.outgoing_shipment_carrier_file_manual') + picking.action_confirm() + + # I check outgoing shipment after stock availablity in refrigerator. + picking.force_assign() + + # I deliver outgoing shipment. + wizard = self.env['stock.transfer_details'].with_context({ + 'active_model': 'stock.picking', + 'active_id': picking.id, + 'active_ids': picking.ids + }).create({ + 'picking_id': picking.id + }) + wizard.do_detailed_transfer() + + # I check shipment details after shipment + # The carrier file must NOT have been generated. + self.assertFalse(picking.carrier_file_generated) + + # I generate the carrier files of my shipment from the wizard + wizard = self.env['delivery.carrier.file.generate'].with_context({ + 'active_ids': picking.ids, + 'active_model': 'stock.picking' + }).create({}) + wizard.action_generate() + + # I check shipment details after manual generation + # The carrier file must have been generated. + self.assertTrue(picking.carrier_file_generated) diff --git a/base_delivery_carrier_files_document/carrier_file_view.xml b/base_delivery_carrier_files_document/views/carrier_file_view.xml similarity index 100% rename from base_delivery_carrier_files_document/carrier_file_view.xml rename to base_delivery_carrier_files_document/views/carrier_file_view.xml