[IMP] delivery: put in pack wizard
We have moved the 'quant.package' view into a wizard, because it's always used as a wizard, and and there was context trouble with the 'Save' button as a button with nale 'write' (the context was mixed with the field, and there were two write action whan "Save button was clicked.
This commit is contained in:
@@ -2,3 +2,4 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import models
|
||||
import wizard
|
||||
|
||||
@@ -24,7 +24,7 @@ invoices from picking, the system is able to add and compute the shipping line.
|
||||
'views/report_shipping.xml',
|
||||
'views/report_deliveryslip.xml',
|
||||
'views/sale_config_settings_views.xml',
|
||||
|
||||
'wizard/choose_delivery_package_views.xml',
|
||||
],
|
||||
'demo': ['data/delivery_demo.xml'],
|
||||
'test': [
|
||||
|
||||
@@ -31,17 +31,19 @@ class StockPackOperation(models.Model):
|
||||
@api.multi
|
||||
def manage_package_type(self):
|
||||
self.ensure_one()
|
||||
view_id = self.env.ref('delivery.choose_delivery_package_view_form').id;
|
||||
return {
|
||||
'name': _('Package Details'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'stock.quant.package',
|
||||
'view_id': self.env.ref('delivery.view_quant_package_form_save').id,
|
||||
'res_model': 'choose.delivery.package',
|
||||
'view_id': view_id,
|
||||
'views': [(view_id, 'form')],
|
||||
'target': 'new',
|
||||
'res_id': self.result_package_id.id,
|
||||
'context': {
|
||||
'default_stock_quant_package_id': self.result_package_id.id,
|
||||
'current_package_carrier_type': self.picking_id.carrier_id.delivery_type if self.picking_id.carrier_id.delivery_type not in ['base_on_rule', 'fixed'] else 'none',
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -120,30 +122,18 @@ class StockPicking(models.Model):
|
||||
|
||||
@api.multi
|
||||
def put_in_pack(self):
|
||||
# TDE FIXME: work in batch, please
|
||||
self.ensure_one()
|
||||
package = super(StockPicking, self).put_in_pack()
|
||||
|
||||
current_package_carrier_type = self.carrier_id.delivery_type if self.carrier_id.delivery_type not in ['base_on_rule', 'fixed'] else 'none'
|
||||
count_packaging = self.env['product.packaging'].search_count([('package_carrier_type', '=', current_package_carrier_type)])
|
||||
if not count_packaging:
|
||||
return False
|
||||
# By default, sum the weights of all package operations contained in this package
|
||||
pack_operation_ids = self.env['stock.pack.operation'].search([('result_package_id', '=', package.id)])
|
||||
package_weight = sum([x.qty_done * x.product_id.weight for x in pack_operation_ids])
|
||||
package.shipping_weight = package_weight
|
||||
|
||||
view_id = self.env.ref('delivery.choose_delivery_package_view_form').id;
|
||||
return {
|
||||
'name': _('Package Details'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'stock.quant.package',
|
||||
'view_id': self.env.ref('delivery.view_quant_package_form_save').id,
|
||||
'res_model': 'choose.delivery.package',
|
||||
'view_id': view_id,
|
||||
'views': [(view_id, 'form')],
|
||||
'target': 'new',
|
||||
'res_id': package.id,
|
||||
'context': {
|
||||
'current_package_carrier_type': current_package_carrier_type,
|
||||
},
|
||||
'current_package_carrier_type': self.carrier_id.delivery_type if self.carrier_id.delivery_type not in ['base_on_rule', 'fixed'] else 'none',
|
||||
}
|
||||
}
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -254,30 +254,6 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="view_quant_package_form_save" model="ir.ui.view">
|
||||
<field name="name">stock.quant.package.form.save</field>
|
||||
<field name="model">stock.quant.package</field>
|
||||
<field eval="99" name="priority"/>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Package">
|
||||
<group>
|
||||
<field name="packaging_id" domain="[('package_carrier_type', '=', context.get('current_package_carrier_type'))]"/>
|
||||
<label for="shipping_weight"/>
|
||||
<div class="o_row">
|
||||
<field name="shipping_weight"/>
|
||||
<span>kg</span>
|
||||
</div>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="write" type="object" string="Save" class="btn btn-sm btn-primary"/>
|
||||
<button string="Discard" special="cancel" class="btn btn-sm btn-default"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="view_move_withweight_form" model="ir.ui.view">
|
||||
<field name="name">stock.move.form.weight</field>
|
||||
<field name="model">stock.move</field>
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
<field name="max_weight"/>
|
||||
<field name="package_carrier_type"/>
|
||||
<field name="shipper_package_code" groups="base.group_no_one"/>
|
||||
<field name="barcode" invisible="1"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import choose_delivery_package
|
||||
@@ -0,0 +1,57 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class ChooseDeliveryPackage(models.TransientModel):
|
||||
_name = 'choose.delivery.package'
|
||||
_description = 'Delivery Package Selection Wizard'
|
||||
|
||||
stock_quant_package_id = fields.Many2one(
|
||||
'stock.quant.package',
|
||||
default=lambda self: self._default_stock_quant_package_id()
|
||||
)
|
||||
delivery_packaging_id = fields.Many2one(
|
||||
'product.packaging',
|
||||
default=lambda self: self._default_delivery_packaging_id()
|
||||
)
|
||||
shipping_weight = fields.Float(
|
||||
string='Shipping Weight',
|
||||
default=lambda self: self._default_shipping_weight()
|
||||
)
|
||||
|
||||
def _default_stock_quant_package_id(self):
|
||||
if self.env.context.get('default_stock_quant_package_id'):
|
||||
return self.env['stock.quant.package'].browse(self.env.context['stock_quant_package_id'])
|
||||
|
||||
def _default_delivery_packaging_id(self):
|
||||
res = None
|
||||
if self.env.context.get('default_delivery_packaging_id'):
|
||||
res = self.env['product.packaging'].browse(self.env.context['default_delivery_packaging_id'])
|
||||
if self.env.context.get('default_stock_quant_package_id'):
|
||||
stock_quant_package = self.env['stock.quant.package'].browse(self.env.context['default_stock_quant_package_id'])
|
||||
res = stock_quant_package.packaging_id
|
||||
return res
|
||||
|
||||
def _default_shipping_weight(self):
|
||||
if self.env.context.get('default_stock_quant_package_id'):
|
||||
stock_quant_package = self.env['stock.quant.package'].browse(self.env.context['default_stock_quant_package_id'])
|
||||
return stock_quant_package.shipping_weight
|
||||
else:
|
||||
picking_id = self.env['stock.picking'].browse(self.env.context['active_id'])
|
||||
pack_operation_product_ids = [po for po in picking_id.pack_operation_product_ids if po.qty_done > 0 and not po.result_package_id]
|
||||
pack_operation_pack_ids = [po for po in picking_id.pack_operation_pack_ids if po.qty_done > 0 and not po.result_package_id]
|
||||
total_weight = sum([po.qty_done * po.product_id.weight for po in pack_operation_product_ids]) + sum([po.package_id.weight for po in pack_operation_pack_ids])
|
||||
return total_weight
|
||||
|
||||
def put_in_pack(self):
|
||||
picking_id = self.env['stock.picking'].browse(self.env.context['active_id'])
|
||||
if not self.stock_quant_package_id:
|
||||
stock_quant_package = picking_id._put_in_pack()
|
||||
self.stock_quant_package_id = stock_quant_package
|
||||
# write shipping weight and product_packaging on 'stock_quant_package' if needed
|
||||
if self.delivery_packaging_id:
|
||||
self.stock_quant_package_id.packaging_id = self.delivery_packaging_id
|
||||
if self.shipping_weight:
|
||||
self.stock_quant_package_id.shipping_weight = self.shipping_weight
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="choose_delivery_package_view_form" model="ir.ui.view">
|
||||
<field name="name">choose.delivery.package.form</field>
|
||||
<field name="model">choose.delivery.package</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Package">
|
||||
<group>
|
||||
<field name="delivery_packaging_id" domain="[('package_carrier_type', '=', context.get('current_package_carrier_type', False))]"/>
|
||||
<label for="shipping_weight" attrs="{'invisible': [('delivery_packaging_id', '=', False)]}"/>
|
||||
<div class="o_row" attrs="{'invisible': [('delivery_packaging_id', '=', False)]}">
|
||||
<field name="shipping_weight"/>
|
||||
<span>kg</span>
|
||||
</div>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="put_in_pack" type="object" string="Save" class="btn btn-sm btn-primary"/>
|
||||
<button string="Discard" special="cancel" class="btn btn-sm btn-default"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -987,7 +987,7 @@ class Picking(models.Model):
|
||||
return backorders
|
||||
|
||||
@api.multi
|
||||
def put_in_pack(self):
|
||||
def _put_in_pack(self):
|
||||
# TDE FIXME: reclean me
|
||||
QuantPackage = self.env["stock.quant.package"]
|
||||
package = False
|
||||
@@ -1019,6 +1019,11 @@ class Picking(models.Model):
|
||||
raise UserError(_('Please process some quantities to put in the pack first!'))
|
||||
return package
|
||||
|
||||
|
||||
@api.multi
|
||||
def put_in_pack(self):
|
||||
return self._put_in_pack()
|
||||
|
||||
@api.multi
|
||||
def button_scrap(self):
|
||||
self.ensure_one()
|
||||
|
||||
Reference in New Issue
Block a user