Faircot action
This commit is contained in:
@@ -7,6 +7,10 @@ def register():
|
||||
rules.AutomationRuleSet,
|
||||
freight_booking.FreightBookingInfo,
|
||||
booking_report.FreightBookingShipmentReport,
|
||||
booking_report.FreightBookingShipmentReportLinkStart,
|
||||
cron.Cron,
|
||||
cron.AutomationCron,
|
||||
module='automation', type_='model')
|
||||
Pool.register(
|
||||
booking_report.FreightBookingShipmentReportLink,
|
||||
module='automation', type_='wizard')
|
||||
|
||||
@@ -5,6 +5,9 @@ from sql.functions import CurrentTimestamp
|
||||
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.pool import Pool
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.wizard import Button, StateTransition, StateView, Wizard
|
||||
from trytond.exceptions import UserError
|
||||
|
||||
|
||||
class FreightBookingShipmentReport(ModelSQL, ModelView):
|
||||
@@ -126,3 +129,65 @@ class FreightBookingShipmentReport(ModelSQL, ModelView):
|
||||
else 'error')
|
||||
for report in reports
|
||||
}
|
||||
|
||||
|
||||
class FreightBookingShipmentReportLinkStart(ModelView):
|
||||
"Link Freight Booking Shipment Report"
|
||||
__name__ = 'freight.booking.shipment.report.link.start'
|
||||
|
||||
bl_number = fields.Char("BL Number", readonly=True)
|
||||
shipment = fields.Many2One(
|
||||
'stock.shipment.in', "Shipment", required=True)
|
||||
|
||||
|
||||
class FreightBookingShipmentReportLink(Wizard):
|
||||
"Link Freight Booking Shipment Report"
|
||||
__name__ = 'freight.booking.shipment.report.link'
|
||||
|
||||
start = StateView(
|
||||
'freight.booking.shipment.report.link.start',
|
||||
'automation.freight_booking_shipment_report_link_start_form',
|
||||
[
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Link', 'link', 'tryton-ok', default=True),
|
||||
])
|
||||
link = StateTransition()
|
||||
|
||||
def default_start(self, fields):
|
||||
Report = Pool().get('freight.booking.shipment.report')
|
||||
active_ids = Transaction().context.get('active_ids') or []
|
||||
reports = Report.browse(active_ids)
|
||||
error_reports = [
|
||||
report for report in reports
|
||||
if report.status == 'error' and report.bl_number]
|
||||
if len(error_reports) > 1:
|
||||
raise UserError(
|
||||
"Link one error line at a time to avoid overwriting the "
|
||||
"shipment BL number.")
|
||||
return {
|
||||
'bl_number': error_reports[0].bl_number if error_reports else None,
|
||||
}
|
||||
|
||||
def transition_link(self):
|
||||
Report = Pool().get('freight.booking.shipment.report')
|
||||
ShipmentIn = Pool().get('stock.shipment.in')
|
||||
active_ids = Transaction().context.get('active_ids') or []
|
||||
reports = Report.browse(active_ids)
|
||||
error_reports = [
|
||||
report for report in reports
|
||||
if report.status == 'error' and report.bl_number]
|
||||
if not error_reports:
|
||||
raise UserError(
|
||||
"Select at least one error line with a BL number.")
|
||||
if len(error_reports) > 1:
|
||||
raise UserError(
|
||||
"Link one error line at a time to avoid overwriting the "
|
||||
"shipment BL number.")
|
||||
|
||||
shipment = self.start.shipment
|
||||
shipment.bl_number = error_reports[0].bl_number
|
||||
ShipmentIn.save([shipment])
|
||||
return 'end'
|
||||
|
||||
def end(self):
|
||||
return 'reload'
|
||||
|
||||
@@ -17,6 +17,21 @@
|
||||
<field name="act_window" ref="act_freight_booking_shipment_report"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="freight_booking_shipment_report_link_start_form">
|
||||
<field name="model">freight.booking.shipment.report.link.start</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">freight_booking_shipment_report_link_start_form</field>
|
||||
</record>
|
||||
<record model="ir.action.wizard" id="act_freight_booking_shipment_report_link">
|
||||
<field name="name">Link to Shipment</field>
|
||||
<field name="wiz_name">freight.booking.shipment.report.link</field>
|
||||
</record>
|
||||
<record model="ir.action.keyword" id="keyword_freight_booking_shipment_report_link">
|
||||
<field name="keyword">form_action</field>
|
||||
<field name="model">freight.booking.shipment.report,-1</field>
|
||||
<field name="action" ref="act_freight_booking_shipment_report_link"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.model.access" id="access_freight_booking_shipment_report">
|
||||
<field name="model">freight.booking.shipment.report</field>
|
||||
<field name="perm_read" eval="False"/>
|
||||
@@ -24,6 +39,21 @@
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_delete" eval="False"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_freight_booking_shipment_report_link_start">
|
||||
<field name="model">freight.booking.shipment.report.link.start</field>
|
||||
<field name="perm_read" eval="False"/>
|
||||
<field name="perm_write" eval="False"/>
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_delete" eval="False"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_freight_booking_shipment_report_link_start_automation">
|
||||
<field name="model">freight.booking.shipment.report.link.start</field>
|
||||
<field name="group" ref="group_automation"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="True"/>
|
||||
<field name="perm_create" eval="True"/>
|
||||
<field name="perm_delete" eval="False"/>
|
||||
</record>
|
||||
<record model="ir.model.access" id="access_freight_booking_shipment_report_automation">
|
||||
<field name="model">freight.booking.shipment.report</field>
|
||||
<field name="group" ref="group_automation"/>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<form>
|
||||
<label name="bl_number"/>
|
||||
<field name="bl_number"/>
|
||||
<label name="shipment"/>
|
||||
<field name="shipment"/>
|
||||
</form>
|
||||
Reference in New Issue
Block a user