diff --git a/oca_dependencies.txt b/oca_dependencies.txt index e69de29b..4c894df8 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -0,0 +1 @@ +stock-logistics-workflow diff --git a/pos_stock_picking_invoice_link/README.rst b/pos_stock_picking_invoice_link/README.rst new file mode 100644 index 00000000..37bc18b2 --- /dev/null +++ b/pos_stock_picking_invoice_link/README.rst @@ -0,0 +1,59 @@ +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +============================== +POS Stock Picking Invoice Link +============================== + +Links POS generated stock moves and pickings to its corresponding invoice +lines. + +Usage +===== + +* Create a POS order with stockable products and invoice option checked. +* If you open invoice form in the backend, you must see the related picking in + the Pickings tab. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/184/10.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* David (https://www.tecnativa.com) + +Do not contact contributors directly about support or help with technical issues. + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/pos_stock_picking_invoice_link/__init__.py b/pos_stock_picking_invoice_link/__init__.py new file mode 100644 index 00000000..cde864ba --- /dev/null +++ b/pos_stock_picking_invoice_link/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models diff --git a/pos_stock_picking_invoice_link/__manifest__.py b/pos_stock_picking_invoice_link/__manifest__.py new file mode 100644 index 00000000..b9174456 --- /dev/null +++ b/pos_stock_picking_invoice_link/__manifest__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Tecnativa S.L. - David Vidal +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'POS Stock Picking Invoice Link', + 'version': '10.0.1.0.0', + 'category': 'Point of Sale', + 'author': 'Tecnativa,' + 'Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/pos', + 'license': 'AGPL-3', + 'depends': [ + 'point_of_sale', + 'stock_picking_invoice_link', + ], + 'application': False, + 'installable': True, +} diff --git a/pos_stock_picking_invoice_link/models/__init__.py b/pos_stock_picking_invoice_link/models/__init__.py new file mode 100644 index 00000000..39beeb1f --- /dev/null +++ b/pos_stock_picking_invoice_link/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import pos_order diff --git a/pos_stock_picking_invoice_link/models/pos_order.py b/pos_stock_picking_invoice_link/models/pos_order.py new file mode 100644 index 00000000..16418e9a --- /dev/null +++ b/pos_stock_picking_invoice_link/models/pos_order.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Tecnativa - David Vidal +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class PosOrder(models.Model): + _inherit = 'pos.order' + + def _prepare_invoice(self): + res = super(PosOrder, self)._prepare_invoice() + res.update({ + 'picking_ids': [(6, 0, self.picking_id.ids)], + }) + return res + + def _action_create_invoice_line(self, line=False, invoice_id=False): + invoice_line = super( + PosOrder, self)._action_create_invoice_line(line, invoice_id) + if not line: + return invoice_line + move = self.env['stock.move'].search([ + ('picking_id', '=', self.picking_id.id), + ('name', '=', line.name)]) + if move: + invoice_line.write({ + 'move_line_ids': [(6, 0, move.ids)], + }) + return invoice_line diff --git a/pos_stock_picking_invoice_link/static/description/icon.png b/pos_stock_picking_invoice_link/static/description/icon.png new file mode 100644 index 00000000..f5deaa3f Binary files /dev/null and b/pos_stock_picking_invoice_link/static/description/icon.png differ diff --git a/pos_stock_picking_invoice_link/tests/__init__.py b/pos_stock_picking_invoice_link/tests/__init__.py new file mode 100644 index 00000000..04b79b41 --- /dev/null +++ b/pos_stock_picking_invoice_link/tests/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import test_point_of_sale_stock_invoice_link diff --git a/pos_stock_picking_invoice_link/tests/test_point_of_sale_stock_invoice_link.py b/pos_stock_picking_invoice_link/tests/test_point_of_sale_stock_invoice_link.py new file mode 100644 index 00000000..b67c14cc --- /dev/null +++ b/pos_stock_picking_invoice_link/tests/test_point_of_sale_stock_invoice_link.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Tecnativa - David Vidal +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests import common + + +@common.at_install(False) +@common.post_install(True) +class TestPointOfSaleStockPickingInvoiceLink(common.HttpCase): + def setUp(self): + super(TestPointOfSaleStockPickingInvoiceLink, self).setUp() + self.partner = self.env['res.partner'].create({ + 'name': 'Mr. Odoo', + }) + self.product_1 = self.env['product.product'].create({ + 'name': 'Test variant 1', + 'standard_price': 1.0, + 'type': 'product', + }) + self.product_2 = self.env['product.product'].create({ + 'name': 'Test variant 1', + 'standard_price': 1.0, + 'type': 'product', + }) + self.PosOrder = self.env['pos.order'] + self.pos_config = self.env.ref('point_of_sale.pos_config_main') + + def test_stock_picking_invoice_link(self): + """The picking is created and the lines are related to their moves""" + self.pos_config.open_session_cb() + pos_order = self.PosOrder.create({ + 'session_id': self.pos_config.current_session_id.id, + 'partner_id': self.partner.id, + 'pricelist_id': self.partner.property_product_pricelist.id, + 'lines': [ + (0, 0, { + 'name': "POSLINE/0001", + 'product_id': self.product_1.id, + 'price_unit': 450, + 'qty': 2.0, + }), + (0, 0, { + 'name': "POSLINE/0002", + 'product_id': self.product_2.id, + 'price_unit': 450, + 'qty': 2.0, + }), + (0, 0, { + 'name': "POSLINE/0003", + 'product_id': self.product_1.id, + 'price_unit': 450, + 'qty': 2.0, + }), + ], + }) + context_make_payment = { + "active_ids": [pos_order.id], + "active_id": pos_order.id, + } + pos_make_payment = self.env['pos.make.payment'].with_context( + context_make_payment).create({'amount': 950}) + context_payment = {'active_id': pos_order.id} + pos_make_payment.with_context(context_payment).check() + pos_order.create_picking() + res = pos_order.action_pos_order_invoice() + invoice = self.env['account.invoice'].browse(res['res_id']) + self.assertTrue(invoice.picking_ids) + for line in invoice.invoice_line_ids: + self.assertEqual(len(line.move_line_ids), 1)