Browse Source

[IMP] Link new picking to original sale order

[ADD] Tests
pull/365/head
Stefan Rijnhart 7 years ago
committed by Sylvain LE GAL
parent
commit
130d5a8dbe
  1. 17
      pos_picking_load/models/pos_order.py
  2. 0
      pos_picking_load/models/stock_move.py
  3. 14
      pos_picking_load/models/stock_picking.py
  4. 1
      pos_picking_load/tests/__init__.py
  5. 72
      pos_picking_load/tests/test_pos_picking_load.py

17
pos_picking_load/models/pos_order.py

@ -30,7 +30,6 @@ class PosOrder(models.Model):
sale_orders = sale_order_obj.search([
('procurement_group_id', '=',
order.origin_picking_id.group_id.id)])
# sale_orders.action_ignore_delivery_exception()
sale_orders.signal_workflow('ship_corrected')
sale_orders.write({'final_pos_order_id': order.id})
@ -41,7 +40,7 @@ class PosOrder(models.Model):
res = super(PosOrder, self).create_from_ui(orders)
orders_with_original_picking = self.search([
('id', 'in', res), ('origin_picking_id', '!=', False),
('state', 'not in', [('draft')])])
('state', '!=', 'draft')])
orders_with_original_picking._handle_orders_with_original_picking()
@ -53,3 +52,17 @@ class PosOrder(models.Model):
if 'origin_picking_id' in ui_order:
res['origin_picking_id'] = ui_order['origin_picking_id']
return res
@api.multi
def create_picking(self):
""" Call super() for each order separately with the origin picking id
in the context. The new picking will be updated accordingly in the
picking's action_confirm() """
for order in self:
if order.picking_id:
continue
if order.origin_picking_id:
order = order.with_context(
origin_picking_id=order.origin_picking_id.id)
super(PosOrder, order).create_picking()
return True

0
pos_picking_load/models/stock_move.py

14
pos_picking_load/models/stock_picking.py

@ -70,3 +70,17 @@ class StockPicking(models.Model):
def load_picking_for_pos(self, picking_id):
picking = self.browse(picking_id)
return self._prepare_pos_order(picking)
@api.multi
def update_from_origin_picking(self, origin_picking):
if origin_picking.group_id:
self.filtered(lambda p: not p.group_id).write({
'group_id': origin_picking.group_id.id})
@api.multi
def action_confirm(self):
""" Assign to same procurement group as the origin picking """
if self.env.context.get('origin_picking_id'):
self.update_from_origin_picking(
self.browse(self.env.context['origin_picking_id']))
return super(StockPicking, self).action_confirm()

1
pos_picking_load/tests/__init__.py

@ -0,0 +1 @@
from . import test_pos_picking_load

72
pos_picking_load/tests/test_pos_picking_load.py

@ -0,0 +1,72 @@
# coding: utf-8
# Copyright (C) 2017: Opener B.V. (https://opener.amsterdam)
# @author: Stefan Rijnhart <stefan@opener.am>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase
class TestPosPickingLoad(TransactionCase):
def test_pos_picking_load(self):
product = self.env.ref('product.product_product_24')
sale_order = self.env['sale.order'].create({
'partner_id': self.env.ref('base.res_partner_1').id,
'order_line': [(0, 0, {
'product_id': product.id,
'price_unit': 6,
'product_uom_qty': 2,
})],
'order_policy': 'picking',
})
sale_order.action_button_confirm()
self.assertTrue(sale_order.picking_ids)
sale_order.picking_ids.picking_type_id.write({
'available_in_pos': True})
config = self.env.ref('point_of_sale.pos_config_main').copy()
config.write({
'picking_type_id': sale_order.picking_ids.picking_type_id.id})
session = self.env['pos.session'].create({
'user_id': self.env.user.id,
'config_id': config.id})
session.signal_workflow('open')
self.env['pos.order'].create_from_ui([{
'to_invoice': False,
'data': {
'user_id': self.env.user.id,
'name': 'Order 00017-002-0003',
'partner_id': sale_order.partner_id.id,
'amount_paid': 12,
'pos_session_id': session.id,
'lines': [[0, 0, {
'product_id': product.id,
'price_unit': 6,
'name': product.name,
'discount': 0,
'qty': 2,
'tax_ids': [[6, False, []]],
}]],
'statement_ids': [[0, 0, {
'journal_id': False,
'amount': 12,
'name': '2017-07-20 13:08:37',
'account_id': config.journal_ids[
0].default_debit_account_id.id,
'statement_id': session.statement_ids[0].id,
}]],
'amount_tax': 0,
'origin_picking_id': sale_order.picking_ids.id,
'uid': '00017-002-0003',
'amount_return': 0,
'sequence_number': 3,
'amount_total': 12,
},
'id': '00017-002-0003',
}])
pos_order = self.env['pos.order'].search(
[('origin_picking_id', 'in', sale_order.picking_ids.ids)])
self.assertTrue(pos_order)
self.assertEqual(pos_order.origin_picking_id.state, 'cancel')
self.assertIn(pos_order.picking_id, sale_order.picking_ids)
self.assertEqual(
pos_order.picking_id.group_id,
pos_order.origin_picking_id.group_id)
Loading…
Cancel
Save