Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] delivery_postlogistics: Print return label in status Ready #2

Open
wants to merge 3 commits into
base: 16.0
Choose a base branch
from
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
1 change: 1 addition & 0 deletions delivery_postlogistics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import models
from . import postlogistics
from . import wizard
12 changes: 12 additions & 0 deletions delivery_postlogistics/models/delivery_carrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,15 @@ def verify_credentials(self):
},
}
return message

def _compute_can_generate_return(self):
res = super(DeliveryCarrier, self)._compute_can_generate_return()
for carrier in self:
if carrier.delivery_type == "postlogistics":
carrier.can_generate_return = True
return res

def postlogistics_get_return_label(
self, picking, tracking_number=None, origin_date=None
):
return self.postlogistics_send_shipping(picking)
6 changes: 6 additions & 0 deletions delivery_postlogistics/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,9 @@ def generate_postlogistics_shipping_labels(self, package_ids=None):
"""Add label generation for PostLogistics"""
self.ensure_one()
return self._generate_postlogistics_label(package_ids=package_ids)

def action_generate_carrier_label(self):
self.ensure_one()
if not self.carrier_id:
raise exceptions.UserError(_("Please, set a carrier."))
self.env["delivery.carrier"].postlogistics_send_shipping(self)
16 changes: 16 additions & 0 deletions delivery_postlogistics/views/stock.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@
<field name="model">stock.picking</field>
<field name="inherit_id" ref="delivery.view_picking_withcarrier_out_form" />
<field name="arch" type="xml">
<field name="state" position="before">
<button
name="action_generate_carrier_label"
help="Create Shipping Label 🚚"
attrs="{'invisible': ['|', '|', ('state', '!=', 'done'), ('delivery_type', '!=', 'postlogistics'), ('picking_type_code', '=', 'incoming')]}"
string="Create Shipping Label 🚚"
type="object"
/>
</field>

<button name="print_return_label" position="attributes">
<attribute
name="attrs"
>{'invisible':['|', ('is_return_picking', '=', False),('picking_type_code', '!=', 'incoming')]}</attribute>
</button>

<xpath expr="//page//group[@name='carrier_data']/.." position="after">
<separator
string="Delivery instructions"
Expand Down
1 change: 1 addition & 0 deletions delivery_postlogistics/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_picking_return
12 changes: 12 additions & 0 deletions delivery_postlogistics/wizard/stock_picking_return.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from odoo import models


class ReturnPicking(models.TransientModel):
_inherit = "stock.return.picking"

def _create_returns(self):

Choose a reason for hiding this comment

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

this will impact all returns
can you add a condition on self.picking_id.delivery_type == "postlogistics"

new_picking, pick_type_id = super(ReturnPicking, self)._create_returns()
if self.picking_id.delivery_type == "postlogistics":
picking = self.env["stock.picking"].browse(new_picking)
picking.write({"carrier_id": self.picking_id.carrier_id.id})
return new_picking, pick_type_id