Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions dbt_shipment_base/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
'name': 'Dreambits Shipments Base',
'version': '12.0.1.0.0',
'depends': ['sale_management','stock'],
'version': '14.0.1.0.0',
'depends': ['sale_management', 'sale_stock'],
'summary': 'Module to have Shipment and Shipment Transporter Models',
'description': """
This module includes shipment and shipment transporter models which will
Expand Down Expand Up @@ -29,4 +29,3 @@
'installable': True,
'auto_install': False,
}

41 changes: 21 additions & 20 deletions dbt_shipment_base/models/Shipment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /usr/bin/env python
# -*- coding: utf-8 -*-

from odoo import models, fields, api
from odoo import models, fields, api
import logging

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -53,7 +53,7 @@ class Shipment(models.Model):

associated_sale = fields.Many2one('sale.order',
string='Associated Sales Order',
required=True, ondelete='cascade')
required=True, ondelete='cascade')
associated_pickings = fields.One2many('stock.picking',
'associated_shipment',
string='Associated Stock Pickings')
Expand All @@ -65,17 +65,16 @@ class Shipment(models.Model):
synced = fields.Boolean('Synced')

@api.model
def create(self, vals):
def create(self, vals):
_logger.info("inside set name")
name = self.env['ir.sequence'].next_by_code('dbt.shipment')

vals["name"] = name
vals["state"] = "ready"
vals["label_state"] = "waiting"
return super(Shipment, self).create(vals)
return super(Shipment, self).create(vals)

@api.model
@api.multi
def name_get(self):
_logger.info("Inside name_get fn")
result = []
Expand All @@ -84,7 +83,7 @@ def name_get(self):
record.name,
record.transporter.name if record.transporter.name else "None",
record.associated_sale.name)
result.append((record.id, name))
result.append((record.id, name))
return result

@api.depends('associated_sale')
Expand All @@ -109,7 +108,7 @@ def update_state(self):
_logger.info("Shipment: " + str(shipments.name)
+ ": calling output method from scheduler")
transporter = shipments.transporter
output_method = getattr(transporter, transporter.get_output_method)
output_method = getattr(transporter, transporter.get_output_method)
output_method(self.associated_shipment)

def action_sync(self):
Expand All @@ -134,13 +133,11 @@ def get_transporters(self):

return name_list

@api.multi
def action_confirm(self):
res = super(CustomSaleOrder, self).action_confirm()
self.create_shipment()
return res

@api.multi
def write(self, vals):
res = super(CustomSaleOrder, self).write(vals)

Expand All @@ -162,6 +159,7 @@ def create_shipment(self):
# lets get the tranporter and make the relevant

# lets get the state. If it is confirmed SO then also proceed
logging.info("***************************************************************************")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove logs from production code

state = self.state
if state == "sale":
# lets check if shipment is already available or not
Expand All @@ -179,6 +177,7 @@ def create_shipment(self):
else:
values = {
'associated_sale': self.id,
# 'shipment_id': self.id,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented ?

}
shipment = self.env['dbt.shipment'].create(values)

Expand All @@ -202,15 +201,15 @@ def create_shipment(self):
_logger.info(pickings)
if pickings:
shipment.associated_pickings = [(6, False, pickings)]
# shipment.shipment_id = self.id
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this commented ?



class CustomStockPicking(models.Model):
_inherit = 'stock.picking'
associated_shipment = fields.Many2one('dbt.shipment', 'Shipment')

@api.multi
def action_done(self):
prev = super(CustomStockPicking, self).action_done()
def _action_done(self):
prev = super(CustomStockPicking, self)._action_done()
_logger.info("We are now inside stock picking")

company = self.env['res.company']._company_default_get('stock.picking')
Expand All @@ -224,35 +223,36 @@ def action_done(self):
generate_method = transporter.generate_file_method
output_method = transporter.get_output_method

_logger.info(generate_method)
_logger.info(output_method)
_logger.info("generate_method %s" % generate_method)
_logger.info("output_method %s" % output_method)

if transporter.transporter_type == "manual":
_logger.info("Manual transportation so no label is generated")
self.associated_shipment.state = "ready_shipment"
else:
# The transporter's method need to update label state and
# state of shipment
_logger.info("now lets call this methods")
_logger.info("now lets call this methods:" )
# we are sending the stock picking object while calling the
# method so it should get the relevant shipment and keep it
# updated
if generate_method and not generate_method == "":
input_function = getattr(transporter, generate_method)
input_function = getattr(transporter, generate_method)
input_function(self)
_logger.info("input_function in _action_done():")

if output_method and not output_method == "":
output_function = getattr(transporter, output_method)
output_function = getattr(transporter, output_method)
output_function(self.associated_shipment)
_logger.info("output_function in _action_done():")
return prev

@api.multi
def write(self, vals):
_logger.info("inside stock picking write")
_logger.info(self)
_logger.info(vals)

result = super(CustomStockPicking, self).write(vals)
result = super(CustomStockPicking, self).write(vals)
for rec in self:

_logger.info(rec)
Expand Down Expand Up @@ -310,7 +310,8 @@ class ShipmentTransporter(models.Model):
should_override_existing = fields.Boolean("Override existing transporter?")

_sql_constraints = [('transporter_code_uniq', 'unique (transporter_code)',
'Duplicate transporter code not allowed !')]
'Duplicate transporter code not allowed !')]


class ShipmentOptions(models.Model):
_name = "dbt.shipment.options"
Expand Down
2 changes: 1 addition & 1 deletion dbt_shipment_base/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
class Company(models.Model):
_inherit = "res.company"

shipment_picking_type_id = fields.Many2one('stock.picking.type', required=1, oldname="shippment_picking_type_id")
shipment_picking_type_id = fields.Many2one('stock.picking.type', required=1)
2 changes: 1 addition & 1 deletion dbt_shipment_base/views/shipment_scheduler.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field ref="dbt_shipment_base.model_dbt_shipment" name="model_id"/>
<field eval="'update_state'" name="function"/>
<field name="code"> model.update_state() </field>
</record>

</data>
Expand Down
1 change: 0 additions & 1 deletion dbt_shipment_base/views/shipment_transporter_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<field name="name">Shipment Transporters</field>
<field name="res_model">dbt.shipment.transporter</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>

Expand Down
1 change: 0 additions & 1 deletion dbt_shipment_base/views/shipment_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<field name="name">Shipments</field>
<field name="res_model">dbt.shipment</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>

Expand Down