Skip to content

Commit

Permalink
Merge pull request #4 from eliusmgani/feat_set_truck_as_dimension
Browse files Browse the repository at this point in the history
chore: remove 'truck' from main doctype 'Cargo Registration' because cargo registration can be assigned to multiple manifest and got multiple trucks
  • Loading branch information
vvsd-dev authored Aug 1, 2024
2 parents b0a8862 + c88359b commit 46e92da
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 34 deletions.
4 changes: 4 additions & 0 deletions vsd_fleet_ms/patches.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pre_model_sync]

[post_model_sync]
vsd_fleet_ms.patches.custom_fields.add_cargo_id_custom_field_on_sales_invoice_item
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import frappe
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields

def execute():
fields = {
"Sales Invoice Item": [
{
"fieldname": "cargo_id",
"fieldtype": "Data",
"label": "Cargo ID",
"insert_after": "cost_center",
"read_only": 1
}
]
}
create_custom_fields(fields, update=True)
frappe.reload_doc("accounts", "doctype", "sales_invoice_item", force=True)
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
{
"default": "Cargo-.YY.-.",
"fieldname": "naming_series",
"fieldtype": "Data",
"fieldtype": "Select",
"hidden": 1,
"label": "Naming Series",
"options": "Cargo-.YY.-.",
Expand Down Expand Up @@ -324,7 +324,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2024-05-09 12:25:15.956076",
"modified": "2024-08-01 12:25:46.066847",
"modified_by": "Administrator",
"module": "VSD Fleet MS",
"name": "Cargo Detail",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"field_order": [
"customer",
"posting_date",
"truck",
"column_break_ta7ta",
"transport_type",
"naming_series",
Expand Down Expand Up @@ -92,19 +91,12 @@
"fieldname": "posting_date",
"fieldtype": "Date",
"label": "Date"
},
{
"fieldname": "truck",
"fieldtype": "Link",
"label": "Truck",
"options": "Truck",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2024-07-29 23:38:13.951558",
"modified": "2024-08-01 11:12:50.486146",
"modified_by": "Administrator",
"module": "VSD Fleet MS",
"name": "Cargo Registration",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def create_sales_invoice(doc, rows):
"uom": frappe.get_value("Item", row["service_item"], "stock_uom"),
"rate": row["rate"],
"description": description,
"cargo_id": row.get("name"),
}
)
item_row_per.append([row, item])
Expand Down
31 changes: 8 additions & 23 deletions vsd_fleet_ms/vsd_fleet_ms/doctype/manifest/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,36 +157,21 @@ def set_truck_dimension(self):
if not has_si_truck_dimension and not has_sii_truck_dimension:
return

cd = DocType("Cargo Detail")
cr = DocType("Cargo Registration")
cargo_details = (
frappe.qb.from_(cd)
.inner_join(cr)
.on(cd.parent == cr.name)
.select(
cr.name.as_("cargo_registration"),
cd.invoice.as_("sales_invoice")
)
.where(
(cd.manifest_number == self.name)
& (cd.docstatus == 1)
)
.groupby(cd.parent, cd.invoice)
).run(as_dict=True)
# Set truck dimension on sales invoice and sales invoice item
for row in self.manifest_cargo_details:
invoice_id = frappe.db.get_value("Cargo Detail", row.cargo_id, "invoice")
invoice_doc = frappe.get_doc("Sales Invoice", invoice_id)

for row in cargo_details:
invoice_doc = frappe.get_doc("Sales Invoice", row.get("sales_invoice"))

if has_si_truck_dimension:
invoice_doc.truck = self.truck
# if has_si_truck_dimension and not invoice_doc.truck:
# invoice_doc.truck = self.truck

if has_sii_truck_dimension:
for d in invoice_doc.items:
d.truck = self.truck
if row.cargo_id == d.cargo_id:
d.truck = self.truck

invoice_doc.save(ignore_permissions=True)

frappe.db.set_value("Cargo Registration", row.get("cargo_registration"), "truck", self.truck)

@frappe.whitelist()
def get_manifests(filter):
Expand Down

0 comments on commit 46e92da

Please sign in to comment.