mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[IMP] delivery_hibou: automatic signature required fields and calculations based on value.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
'name': 'Delivery Hibou',
|
||||
'summary': 'Adds underlying pinnings for things like "RMA Return Labels"',
|
||||
'version': '11.0.1.1.0',
|
||||
'version': '11.0.1.2.0',
|
||||
'author': "Hibou Corp.",
|
||||
'category': 'Stock',
|
||||
'license': 'AGPL-3',
|
||||
|
||||
@@ -9,6 +9,9 @@ class DeliveryCarrier(models.Model):
|
||||
automatic_insurance_value = fields.Float(string='Automatic Insurance Value',
|
||||
help='Will be used during shipping to determine if the '
|
||||
'picking\'s value warrants insurance being added.')
|
||||
automatic_sig_req_value = fields.Float(string='Automatic Signature Required Value',
|
||||
help='Will be used during shipping to determine if the '
|
||||
'picking\'s value warrants signature required being added.')
|
||||
procurement_priority = fields.Selection(PROCUREMENT_PRIORITIES,
|
||||
string='Procurement Priority',
|
||||
help='Priority for this carrier. Will affect pickings '
|
||||
@@ -31,6 +34,21 @@ class DeliveryCarrier(models.Model):
|
||||
value = 0.0
|
||||
return value
|
||||
|
||||
def get_signature_required(self, order=None, picking=None):
|
||||
value = 0.0
|
||||
if order:
|
||||
if order.order_line:
|
||||
value = sum(order.order_line.filtered(lambda l: l.type != 'service').mapped('price_subtotal'))
|
||||
else:
|
||||
return False
|
||||
if picking:
|
||||
value = picking.declared_value()
|
||||
if picking.require_signature == 'no':
|
||||
return False
|
||||
elif picking.require_signature == 'yes':
|
||||
return True
|
||||
return self.automatic_sig_req_value and value >= self.automatic_sig_req_value
|
||||
|
||||
def get_third_party_account(self, order=None, picking=None):
|
||||
if order and order.shipping_account_id:
|
||||
return order.shipping_account_id
|
||||
|
||||
@@ -34,6 +34,12 @@ class StockPicking(models.Model):
|
||||
('no', 'No'),
|
||||
], string='Require Insurance', default='auto',
|
||||
help='If your carrier supports it, auto should be calculated off of the "Automatic Insurance Value" field.')
|
||||
require_signature = fields.Selection([
|
||||
('auto', 'Automatic'),
|
||||
('yes', 'Yes'),
|
||||
('no', 'No'),
|
||||
], string='Require Signature', default='auto',
|
||||
help='If your carrier supports it, auto should be calculated off of the "Automatic Signature Required Value" field.')
|
||||
package_carrier_tracking_ref = fields.Char(string='Package Tracking Numbers', compute='_compute_package_carrier_tracking_ref')
|
||||
|
||||
@api.depends('package_ids.carrier_tracking_ref')
|
||||
|
||||
@@ -28,8 +28,10 @@ class TestDeliveryHibou(common.TransactionCase):
|
||||
|
||||
# Assign values to new Carrier
|
||||
test_insurance_value = 600
|
||||
test_sig_req_value = 300
|
||||
test_procurement_priority = '1'
|
||||
self.carrier.automatic_insurance_value = test_insurance_value
|
||||
self.carrier.automatic_sig_req_value = test_sig_req_value
|
||||
self.carrier.procurement_priority = test_procurement_priority
|
||||
|
||||
|
||||
@@ -71,7 +73,9 @@ class TestDeliveryHibou(common.TransactionCase):
|
||||
|
||||
def test_carrier_hibou_out(self):
|
||||
test_insurance_value = 4000
|
||||
test_sig_req_value = 4000
|
||||
self.carrier.automatic_insurance_value = test_insurance_value
|
||||
self.carrier.automatic_sig_req_value = test_sig_req_value
|
||||
|
||||
picking_out = self.env.ref('stock.outgoing_shipment_main_warehouse')
|
||||
self.assertEqual(picking_out.state, 'assigned')
|
||||
@@ -87,21 +91,29 @@ class TestDeliveryHibou(common.TransactionCase):
|
||||
# The 'value' is assumed to be all of the product value from the initial demand.
|
||||
self.assertEqual(picking_out.declared_value(), 15.0 * 3300.0)
|
||||
self.assertEqual(picking_out.carrier_id.get_insurance_value(picking=picking_out), picking_out.declared_value())
|
||||
self.assertTrue(picking_out.carrier_id.get_signature_required(picking=picking_out))
|
||||
|
||||
# Workflow where user explicitly opts out of insurance on the picking level.
|
||||
picking_out.require_insurance = 'no'
|
||||
picking_out.require_signature = 'no'
|
||||
self.assertEqual(picking_out.carrier_id.get_insurance_value(picking=picking_out), 0.0)
|
||||
self.assertFalse(picking_out.carrier_id.get_signature_required(picking=picking_out))
|
||||
picking_out.require_insurance = 'auto'
|
||||
picking_out.require_signature = 'auto'
|
||||
|
||||
# Lets choose to only delivery one piece at the moment.
|
||||
# This does not meet the minimum on the carrier to have insurance value.
|
||||
picking_out.move_line_ids.qty_done = 1.0
|
||||
self.assertEqual(picking_out.declared_value(), 3300.0)
|
||||
self.assertEqual(picking_out.carrier_id.get_insurance_value(picking=picking_out), 0.0)
|
||||
self.assertFalse(picking_out.carrier_id.get_signature_required(picking=picking_out))
|
||||
# Workflow where user opts in to insurance.
|
||||
picking_out.require_insurance = 'yes'
|
||||
picking_out.require_signature = 'yes'
|
||||
self.assertEqual(picking_out.carrier_id.get_insurance_value(picking=picking_out), 3300.0)
|
||||
self.assertTrue(picking_out.carrier_id.get_signature_required(picking=picking_out))
|
||||
picking_out.require_insurance = 'auto'
|
||||
picking_out.require_signature = 'auto'
|
||||
|
||||
# Test with picking having 3rd party account.
|
||||
self.assertEqual(picking_out.carrier_id.get_third_party_account(picking=picking_out), None)
|
||||
@@ -128,9 +140,9 @@ class TestDeliveryHibou(common.TransactionCase):
|
||||
picking_in.carrier_id = self.carrier
|
||||
# This relies heavily on the 'stock' demo data.
|
||||
# Should only have a single move_line_ids and it should not be done at all.
|
||||
self.assertEqual(picking_in.move_line_ids.mapped('qty_done'), [0.0, 0.0, 0.0])
|
||||
self.assertEqual(picking_in.move_line_ids.mapped('product_uom_qty'), [35.0, 10.0, 12.0])
|
||||
self.assertEqual(picking_in.move_line_ids.mapped('product_id.standard_price'), [55.0, 35.0, 1700.0])
|
||||
self.assertEqual(picking_in.move_line_ids.mapped('qty_done'), [0.0])
|
||||
self.assertEqual(picking_in.move_line_ids.mapped('product_uom_qty'), [35.0])
|
||||
self.assertEqual(picking_in.move_line_ids.mapped('product_id.standard_price'), [55.0])
|
||||
|
||||
self.assertEqual(picking_in.carrier_id._classify_picking(picking=picking_in), 'in')
|
||||
self.assertEqual(picking_in.carrier_id.get_shipper_company(picking=picking_in),
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='integration_level']" position="after">
|
||||
<field name="automatic_insurance_value"/>
|
||||
<field name="automatic_sig_req_value"/>
|
||||
<field name="procurement_priority"/>
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='carrier_id']" position="before">
|
||||
<field name="require_insurance" attrs="{'readonly': [('state', 'in', ('done', 'cancel'))]}"/>
|
||||
<field name="require_signature" attrs="{'readonly': [('state', 'in', ('done', 'cancel'))]}"/>
|
||||
<field name="shipping_account_id" attrs="{'readonly': [('state', 'in', ('done', 'cancel'))]}"
|
||||
options="{'no_create': True, 'no_open': True}"
|
||||
domain="['|', ('partner_id', '=', False), ('partner_id', '=', partner_id)]"/>
|
||||
|
||||
Reference in New Issue
Block a user