Skip to content

Instantly share code, notes, and snippets.

@ray-odoo
Created July 21, 2022 22:40
Show Gist options
  • Save ray-odoo/f363fb5037c9bf0b6c69e21fd27591b9 to your computer and use it in GitHub Desktop.
Save ray-odoo/f363fb5037c9bf0b6c69e21fd27591b9 to your computer and use it in GitHub Desktop.
Landed Cost - bringing the label from the Vendor Bill over to a custom field on the Valuation Adjustment Line
# Example Vendor Bill
Track "Track", 100 units x $10 = $1,000
Train "Train", 250 units x $7 = $1,750
Design "for Track", 1 unit x $195
Freight "for the PO", 1 unit x $595
Overcharge "for Track", 100 units x price_unit
Overcharge, "for Train", 250 units x price_unit
# We want to know, for each LC, should it be applied to one product, or both
# After this we need to delete the lines where there isn't a match - no design on train, no track overchange on train, etc
# Add a SUM so we can verify the total
# depends
cost_id.picking_ids
# compute
for record in self:
lc_product_id = record.cost_line_id.product_id
lc_quantity = record.quantity
label = False
# loop and look for full matches:
for invoice_line in record.cost_line_id.cost_id.vendor_bill_id.invoice_line_ids.filtered(lambda r: r.is_landed_costs_line == True):
bill_product_id = invoice_line.product_id
bill_quantity = invoice_line.quantity
if lc_quantity == bill_quantity and lc_product_id.id == bill_product_id.id:
label = invoice_line.name
# loop and look for partial matches:
for invoice_line in record.cost_line_id.cost_id.vendor_bill_id.invoice_line_ids.filtered(lambda r: r.is_landed_costs_line == True):
bill_product_id = invoice_line.product_id
bill_quantity = invoice_line.quantity
if not label and lc_product_id.id == bill_product_id.id:
label = invoice_line.name
record['x_label'] = label or ''
@ray-odoo
Copy link
Author

ray-odoo commented Jul 21, 2022

Vendor Bill:

image

Landed Cost:

image

image

Inventory BEFORE:

image

Inventory AFTER:

image

Allocation of Expenses:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment