forked from OCA/hr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request OCA#261 from sebalix/bsibso-1107_picking_update_de…
…livery_date BSIBSO-1107: Change the delivery date of a picking
- Loading branch information
Showing
10 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
74 changes: 74 additions & 0 deletions
74
odoo/local-src/specific_sale/tests/test_picking_update_delivery_date.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
25 changes: 25 additions & 0 deletions
25
odoo/local-src/specific_sale/wizard/picking_update_delivery_date.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
26 changes: 26 additions & 0 deletions
26
odoo/local-src/specific_sale/wizard/picking_update_delivery_date.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -431,3 +431,4 @@ migration: | |
- report_xlsx_helper | ||
#### local-src | ||
- specific_security | ||
- specific_sale |