Bug col_width
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
from trytond.pool import Pool
|
||||
from . import automation,rules,freight_booking,cron #, document
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
automation.AutomationDocument,
|
||||
rules.AutomationRuleSet,
|
||||
freight_booking.FreightBookingInfo,
|
||||
cron.Cron,
|
||||
cron.AutomationCron,
|
||||
module='automation', type_='model')
|
||||
from trytond.pool import Pool
|
||||
from . import automation,rules,freight_booking,booking_report,cron #, document
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
automation.AutomationDocument,
|
||||
rules.AutomationRuleSet,
|
||||
freight_booking.FreightBookingInfo,
|
||||
booking_report.FreightBookingShipmentReport,
|
||||
cron.Cron,
|
||||
cron.AutomationCron,
|
||||
module='automation', type_='model')
|
||||
|
||||
128
modules/automation/booking_report.py
Normal file
128
modules/automation/booking_report.py
Normal file
@@ -0,0 +1,128 @@
|
||||
import json
|
||||
|
||||
from sql import Literal, Null
|
||||
from sql.functions import CurrentTimestamp
|
||||
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.pool import Pool
|
||||
|
||||
|
||||
class FreightBookingShipmentReport(ModelSQL, ModelView):
|
||||
"Freight Booking Shipment Report"
|
||||
__name__ = 'freight.booking.shipment.report'
|
||||
|
||||
automation_document = fields.Many2One(
|
||||
'automation.document', "Automation Document")
|
||||
bl_number = fields.Function(fields.Char("BL Number"), 'get_bl_number')
|
||||
shipment = fields.Function(fields.Many2One(
|
||||
'stock.shipment.in', "Shipment"), 'get_shipment')
|
||||
status = fields.Function(fields.Selection([
|
||||
('found', "Found"),
|
||||
('error', "Error"),
|
||||
], "Status"), 'get_status')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
cls._order = [
|
||||
('id', 'DESC'),
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def table_query(cls):
|
||||
AutomationDocument = Pool().get('automation.document')
|
||||
document = AutomationDocument.__table__()
|
||||
|
||||
return document.select(
|
||||
Literal(None).as_('create_uid'),
|
||||
CurrentTimestamp().as_('create_date'),
|
||||
Literal(None).as_('write_uid'),
|
||||
Literal(None).as_('write_date'),
|
||||
document.id.as_('id'),
|
||||
document.id.as_('automation_document'),
|
||||
where=(
|
||||
(document.type == 'weight_report')
|
||||
& (document.metadata_json != Null)))
|
||||
|
||||
@classmethod
|
||||
def _extract_bl_number(cls, metadata_json):
|
||||
if not metadata_json:
|
||||
return None
|
||||
try:
|
||||
metadata = json.loads(str(metadata_json))
|
||||
except (TypeError, ValueError):
|
||||
return None
|
||||
|
||||
def find_value(value):
|
||||
if isinstance(value, dict):
|
||||
for key in (
|
||||
'bl_no', 'bl_number', 'bl', 'BL_Number',
|
||||
'BL number', 'B/L No'):
|
||||
bl_number = value.get(key)
|
||||
if bl_number:
|
||||
return str(bl_number).strip()
|
||||
for item in value.values():
|
||||
bl_number = find_value(item)
|
||||
if bl_number:
|
||||
return bl_number
|
||||
elif isinstance(value, list):
|
||||
for item in value:
|
||||
bl_number = find_value(item)
|
||||
if bl_number:
|
||||
return bl_number
|
||||
return None
|
||||
|
||||
return find_value(metadata)
|
||||
|
||||
@classmethod
|
||||
def _get_report_data(cls, reports):
|
||||
ShipmentIn = Pool().get('stock.shipment.in')
|
||||
bl_numbers = {}
|
||||
|
||||
for report in reports:
|
||||
document = report.automation_document
|
||||
bl_number = cls._extract_bl_number(
|
||||
document.metadata_json if document else None)
|
||||
bl_numbers[report.id] = bl_number
|
||||
|
||||
shipments_by_bl = {}
|
||||
for bl_number in {b for b in bl_numbers.values() if b}:
|
||||
shipments = ShipmentIn.search([
|
||||
('bl_number', '=', bl_number),
|
||||
], limit=1)
|
||||
if not shipments:
|
||||
shipments = ShipmentIn.search([
|
||||
('bl_number', 'ilike', bl_number),
|
||||
], limit=1)
|
||||
shipments_by_bl[bl_number] = shipments[0] if shipments else None
|
||||
|
||||
return bl_numbers, shipments_by_bl
|
||||
|
||||
@classmethod
|
||||
def get_bl_number(cls, reports, name):
|
||||
bl_numbers, _ = cls._get_report_data(reports)
|
||||
return bl_numbers
|
||||
|
||||
@classmethod
|
||||
def get_shipment(cls, reports, name):
|
||||
bl_numbers, shipments_by_bl = cls._get_report_data(reports)
|
||||
return {
|
||||
report.id: (
|
||||
shipments_by_bl[bl_numbers[report.id]].id
|
||||
if bl_numbers[report.id]
|
||||
and shipments_by_bl.get(bl_numbers[report.id])
|
||||
else None)
|
||||
for report in reports
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def get_status(cls, reports, name):
|
||||
bl_numbers, shipments_by_bl = cls._get_report_data(reports)
|
||||
return {
|
||||
report.id: (
|
||||
'found'
|
||||
if bl_numbers[report.id]
|
||||
and shipments_by_bl.get(bl_numbers[report.id])
|
||||
else 'error')
|
||||
for report in reports
|
||||
}
|
||||
43
modules/automation/booking_report.xml
Normal file
43
modules/automation/booking_report.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0"?>
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="freight_booking_shipment_report_tree">
|
||||
<field name="model">freight.booking.shipment.report</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">freight_booking_shipment_report_tree</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.act_window" id="act_freight_booking_shipment_report">
|
||||
<field name="name">Freight Booking Shipment Report</field>
|
||||
<field name="res_model">freight.booking.shipment.report</field>
|
||||
</record>
|
||||
<record model="ir.action.act_window.view" id="act_freight_booking_shipment_report_view1">
|
||||
<field name="sequence" eval="10"/>
|
||||
<field name="view" ref="freight_booking_shipment_report_tree"/>
|
||||
<field name="act_window" ref="act_freight_booking_shipment_report"/>
|
||||
</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"/>
|
||||
<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_automation">
|
||||
<field name="model">freight.booking.shipment.report</field>
|
||||
<field name="group" ref="group_automation"/>
|
||||
<field name="perm_read" eval="True"/>
|
||||
<field name="perm_write" eval="False"/>
|
||||
<field name="perm_create" eval="False"/>
|
||||
<field name="perm_delete" eval="False"/>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
name="Freight Booking Shipment Report"
|
||||
action="act_freight_booking_shipment_report"
|
||||
parent="menu_automation"
|
||||
sequence="11"
|
||||
id="menu_freight_booking_shipment_report" />
|
||||
</data>
|
||||
</tryton>
|
||||
@@ -7,4 +7,5 @@ depends:
|
||||
xml:
|
||||
automation.xml
|
||||
freight_booking.xml
|
||||
cron.xml
|
||||
booking_report.xml
|
||||
cron.xml
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<tree>
|
||||
<field name="bl_number"/>
|
||||
<field name="status" widget="badge"
|
||||
badge_colors="found:#16a34a,Found:#16a34a,error:#ef4444,Error:#ef4444"/>
|
||||
<field name="shipment"/>
|
||||
<field name="automation_document"/>
|
||||
</tree>
|
||||
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
<form col="12">
|
||||
<group id="sample_summary" colspan="12" col="8"
|
||||
col_widths="min-content,1.2fr,min-content,0.8fr,min-content,0.8fr,min-content,0.8fr">
|
||||
<group id="sample_summary" colspan="12" col="8">
|
||||
<label name="reference"/>
|
||||
<field name="reference" width="220" xexpand="0" xfill="0"/>
|
||||
<label name="state"/>
|
||||
@@ -11,8 +10,7 @@
|
||||
<label name="recommended_decision"/>
|
||||
<field name="recommended_decision" width="140" xexpand="0" xfill="0"/>
|
||||
</group>
|
||||
<group id="sample_actions" colspan="12" col="9"
|
||||
col_widths="1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr,1fr">
|
||||
<group id="sample_actions" colspan="12" col="9">
|
||||
<button name="receive" string="Receive"/>
|
||||
<button name="send_to_lab" string="Send to lab"/>
|
||||
<button name="review" string="Review"/>
|
||||
@@ -23,9 +21,8 @@
|
||||
<button name="archive" string="Archive"/>
|
||||
<button name="reset_to_requested" string="Reset"/>
|
||||
</group>
|
||||
<group id="sample_left_column" colspan="7" col="1" col_widths="1fr">
|
||||
<group id="sample_identity" string="Sample identity" colspan="1" col="4"
|
||||
col_widths="min-content,1fr,min-content,1fr">
|
||||
<group id="sample_left_column" colspan="7" col="1">
|
||||
<group id="sample_identity" string="Sample identity" colspan="1" col="4">
|
||||
<label name="direction"/>
|
||||
<field name="direction" width="160" xexpand="0" xfill="0"/>
|
||||
<label name="sample_type"/>
|
||||
@@ -45,8 +42,7 @@
|
||||
<label name="public_coffee_type"/>
|
||||
<field name="public_coffee_type" width="140" xexpand="0" xfill="0"/>
|
||||
</group>
|
||||
<group id="sample_storage" string="Sample storage" colspan="1" col="4"
|
||||
col_widths="min-content,1fr,min-content,1fr">
|
||||
<group id="sample_storage" string="Sample storage" colspan="1" col="4">
|
||||
<label name="quantity"/>
|
||||
<field name="quantity" width="120" xexpand="0" xfill="0"/>
|
||||
<label name="unit"/>
|
||||
@@ -54,8 +50,7 @@
|
||||
<label name="storage_location"/>
|
||||
<field name="storage_location" colspan="3"/>
|
||||
</group>
|
||||
<group id="sample_lab" string="Lab delegation" colspan="1" col="6"
|
||||
col_widths="min-content,max-content,min-content,1fr,min-content,max-content">
|
||||
<group id="sample_lab" string="Lab delegation" colspan="1" col="6">
|
||||
<label name="delegated_to_lab"/>
|
||||
<field name="delegated_to_lab" xexpand="0" xfill="0"/>
|
||||
<label name="lab"/>
|
||||
@@ -64,9 +59,8 @@
|
||||
<field name="lab_due_date" width="120" xexpand="0" xfill="0"/>
|
||||
</group>
|
||||
</group>
|
||||
<group id="sample_right_column" colspan="5" col="1" col_widths="1fr">
|
||||
<group id="sample_lifecycle" string="Lifecycle" colspan="1" col="4"
|
||||
col_widths="min-content,max-content,min-content,max-content">
|
||||
<group id="sample_right_column" colspan="5" col="1">
|
||||
<group id="sample_lifecycle" string="Lifecycle" colspan="1" col="4">
|
||||
<label name="requested_date"/>
|
||||
<field name="requested_date" width="120" xexpand="0" xfill="0"/>
|
||||
<label name="received_date"/>
|
||||
@@ -84,8 +78,7 @@
|
||||
<label name="expires_soon"/>
|
||||
<field name="expires_soon" xexpand="0" xfill="0"/>
|
||||
</group>
|
||||
<group id="sample_quality" string="Quality values" colspan="1" col="4"
|
||||
col_widths="min-content,max-content,min-content,max-content">
|
||||
<group id="sample_quality" string="Quality values" colspan="1" col="4">
|
||||
<label name="moisture"/>
|
||||
<field name="moisture" width="90" xexpand="0" xfill="0"/>
|
||||
<label name="screen_size"/>
|
||||
|
||||
Reference in New Issue
Block a user