hive_sales_sync_costarica/models/docr/items.py
Marvin Vallecillo a2663d15be First commit
2024-07-17 04:19:28 -06:00

37 lines
1.5 KiB
Python

from .coupon import ItemCouponModel
from orm import fields, model
class ItemModel(model.Model):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.item_id = fields.FixedValue(value=1)
self.item_type = fields.FixedValue(value='product')
self.item_code = fields.ThisModelValue(db_column='ProductCode')
self.description = fields.ThisModelValue(db_column='OrdLineDescription')
self.quantity = fields.ThisModelValue(db_column='Quantity')
self.cost = fields.ThisModelDecimalValue(
db_column='IFC', decimal_places=4
)
self.unit_price = fields.ThisModelDecimalValue(
db_column='Price/Quantity', db_alias='unit_price', decimal_places=4
)
self.net_price = fields.ThisModelDecimalValue(
db_column='Price', decimal_places=4
)
self.total_price = fields.ThisModelDecimalValue(
db_column='OrdLineFinalPrice', decimal_places=4
)
self.taxes = fields.ThisModelValueCustomSerializer(
db_column='OrdLineTaxAmt',
value_serialized=lambda v: [{"code": 1, "amount": round(float(v), 4)}]
)
self.discounts = ItemCouponModel(
['Location_Code', 'Order_Date', 'Order_Number', 'Line_Number'],
raise_not_found_error=False
)
class Conf:
db_table = 'POS.dbo.Order_Lines'
filters = ('Location_Code', 'Order_Date', 'Order_Number')