Skip to content

Commit

Permalink
Merge pull request OCA#261 from sebalix/bsibso-1107_picking_update_de…
Browse files Browse the repository at this point in the history
…livery_date

BSIBSO-1107: Change the delivery date of a picking
  • Loading branch information
simahawk committed Nov 27, 2018
2 parents 8c10692 + 51bff30 commit 606d73a
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 0 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Latest (Unreleased)
* BSIBSO-1079: generate recurring invoices 10d in advance (delay can be
adjusted in the cron parameters)

* BSIBSO-1107: Change the delivery date of a picking

**Bugfixes**
* BSIBSO-1092: fix invoicing of sales with MRC

Expand Down
2 changes: 2 additions & 0 deletions odoo/local-src/specific_sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
'data': [
'wizard/sale_refusal_view.xml',
'wizard/mrp_invoicing_view.xml',
'wizard/picking_update_delivery_date.xml',
'views/partner.xml',
'views/sale.xml',
'views/sale_order_line.xml',
'views/account_invoice.xml',
'views/report_invoice.xml',
'views/sale_subscription_views.xml',
'views/product.xml',
'views/stock_picking.xml',
'data/ir_sequence.xml'
],
'test': [],
Expand Down
1 change: 1 addition & 0 deletions odoo/local-src/specific_sale/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from . import sale_subscription
from . import subscription_template
from . import account_analytic_account
from . import stock_picking
43 changes: 43 additions & 0 deletions odoo/local-src/specific_sale/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo import api, models


class StockPicking(models.Model):
_inherit = 'stock.picking'

@api.multi
def action_update_delivery_date(self):
"""Open a wizard to change the delivery date on a done picking."""
self.ensure_one()
if self.state == 'done':
return {
'name': "Update the delivery date",
'view_type': 'form',
'view_mode': 'form',
'res_model': 'wizard.picking.update.delivery_date',
'view_id': False,
'target': 'new',
'type': 'ir.actions.act_window',
}
return True

@api.multi
def update_delivery_date(self, delivery_date):
"""Change the `date_done` field of the done pickings in `self` and
`date` field of all the related done moves with `delivery_date`.
:param delivery_date: datetime string
:return: True
"""

def filter_done(o):
return o.state == 'done'

done_pickings = self.filtered(filter_done)
done_pickings.write({'date_done': delivery_date})
done_moves = done_pickings.mapped('move_lines').filtered(filter_done)
done_moves.write({'date': delivery_date})
return True
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo.tests import common


class TestPickingUpdateDeliveryDate(common.SavepointCase):

@classmethod
def setUpClass(cls):
super(TestPickingUpdateDeliveryDate, cls).setUpClass()
cls.product_model = cls.env['product.product']
cls.picking_model = cls.env['stock.picking']
cls.move_model = cls.env['stock.move']
# Get some basic data
cls.picking_type_out = cls.env.ref('stock.picking_type_out')
cls.stock_location = cls.env.ref('stock.stock_location_stock')
cls.customer_location = cls.env.ref('stock.stock_location_customers')
# Create test data
cls.product = cls.product_model.create(
{'name': 'Test Product', 'type': 'product'})
cls.supplier = cls.env['res.partner'].create({
'name': u"Test Supplier",
'supplier': True,
})
cls.picking_out = cls.picking_model.create({
'partner_id': cls.supplier.id,
'picking_type_id': cls.picking_type_out.id,
'location_id': cls.stock_location.id,
'location_dest_id': cls.customer_location.id,
})
cls.move_model.create({
'name': cls.product.name,
'product_id': cls.product.id,
'product_uom_qty': 10,
'product_uom': cls.product.uom_id.id,
'picking_id': cls.picking_out.id,
'location_id': cls.stock_location.id,
'location_dest_id': cls.customer_location.id,
})
# Put qty in stock
cls.change_product_qty(cls.product, 10)
# Validate the picking
cls.picking_out.action_confirm()
cls.picking_out.action_assign()
cls.picking_out.action_done()
# Create the wizard
wiz_update_model = cls.env['wizard.picking.update.delivery_date']
wiz_update_vals = wiz_update_model.with_context(
active_model=cls.picking_out._name,
active_id=cls.picking_out.id).default_get(['picking_id'])
cls.wiz_update = wiz_update_model.create(wiz_update_vals)

@classmethod
def change_product_qty(cls, product, new_qty):
wiz_model = cls.env['stock.change.product.qty']
vals = wiz_model.with_context(
active_model=product._name, active_id=product.id).default_get([])
vals['new_qty'] = new_qty
wiz = wiz_model.create(vals)
wiz.change_product_qty()

def test_update_delivery_date(self):
new_delivery_date = '2018-11-18 00:00:00'
self.wiz_update.delivery_date = new_delivery_date
self.wiz_update.validate()
date_done = self.picking_out.date_done
delivery_date = new_delivery_date
self.assertEqual(date_done, delivery_date)
for move in self.picking_out.move_lines:
move_date = move.date
self.assertEqual(move.state, 'done')
self.assertEqual(move_date, delivery_date)
19 changes: 19 additions & 0 deletions odoo/local-src/specific_sale/views/stock_picking.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 Camptocamp SA
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>

<record id="view_picking_form" model="ir.ui.view">
<field name="name">stock.picking.form.inherit</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<button name="button_scrap" position="after">
<button name="action_update_delivery_date" type="object"
string="Change delivery date"
attrs="{'invisible': [('state', '!=', 'done')]}"/>
</button>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions odoo/local-src/specific_sale/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import sale_refusal
from . import mrp_invoicing
from . import picking_update_delivery_date
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)

from odoo import api, fields, models


class WizardPickingUpdateDeliverydate(models.TransientModel):
_name = 'wizard.picking.update.delivery_date'
_description = "Update the delivery date on done pickings."

picking_id = fields.Many2one(
'stock.picking', string="Picking", readonly=True,
default=lambda cls: cls.env.context.get('active_id'))
delivery_date = fields.Date("New delivery date")

@api.onchange('picking_id')
def onchange_picking_id(self):
self.delivery_date = self.picking_id.date_done

@api.multi
def validate(self):
self.ensure_one()
self.picking_id.update_delivery_date(self.delivery_date)
return True
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 Camptocamp SA
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>

<record id="wizard_picking_update_delivery_date_form" model="ir.ui.view">
<field name="name">wizard.picking.update.delivery.date.form</field>
<field name="model">wizard.picking.update.delivery_date</field>
<field name="arch" type="xml">
<form string="Update the delivery_date">
<sheet>
<group name="info">
<field name="picking_id"/>
<field name="delivery_date"/>
</group>
</sheet>
<footer>
<button name="validate" type="object"
string="Validate" class="btn-primary"/>
<button special="cancel" string="Cancel" class="btn-default"/>
</footer>
</form>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions odoo/migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,4 @@ migration:
- report_xlsx_helper
#### local-src
- specific_security
- specific_sale

0 comments on commit 606d73a

Please sign in to comment.