class AccountReconcileVATLine(Model): _name = "account.reconcile.vat.line" _name_field = "rec_id" _fields = { "rec_id": fields.Many2One("account.reconcile.vat", "Reconcile ID", required=True, on_delete="cascade"), "tax_date": fields.Date("Tax Date"), "related_id": fields.Reference( [["account.invoice", "Invoice"], ["account.payment", "Payment"], ["account.move", "Move"]], "Related To", required=True), "tax_no": fields.Char("Tax No."), "contact_id": fields.Many2One("contact", "Contact", required=True), "tax_base": fields.Decimal("Tax Base", required=True), "tax_amount": fields.Decimal("Tax Amount", required=True), "move_line_id": fields.Many2One("account.move.line", "Move Line ID", required=True), #Use To Reconcile } _order = "tax_date desc"
class BarcodeSafeOutLine(Model): _name = "barcode.safe.out.line" _transient = True _fields = { "wizard_id": fields.Many2One("barcode.safe.out", "Wizard", required=True, on_delete="cascade"), "product_id": fields.Many2One("product", "Product", required=True), "qty": fields.Decimal("Transfer Qty", required=True), "uom_id": fields.Many2One("uom", "UoM", required=True), "qty2": fields.Decimal("Transfer Secondary Qty"), "lot_id": fields.Many2One("stock.lot", "Lot / Serial Number"), "container_from_id": fields.Many2One("stock.container", "From Container"), "container_to_id": fields.Many2One("stock.container", "To Container"), "production_id": fields.Many2One("production.order", "Production Order"), }
class BarcodeQCLine(Model): _name = "barcode.qc.line" _transient = True _fields = { "barcode_id": fields.Many2One("barcode.qc", "Barcode", required=True, on_delete="cascade"), "test_id": fields.Many2One("qc.test", "QC Test", required=True), "sample_qty": fields.Decimal("Sampling Qty", scale=6), "value": fields.Char("Value"), "min_value": fields.Decimal("Min Value", function="_get_related", function_context={"path": "test_id.min_value"}), "max_value": fields.Decimal("Max Value", function="_get_related", function_context={"path": "test_id.max_value"}), "result": fields.Selection([["yes", "Yes"], ["no", "No"], ["na", "N/A"]], "Result", required=True), "prod_qc_id": fields.Many2One("production.qc", "Production QC"), }
class BarcodeIssueLine(Model): _name = "barcode.issue.line" _transient = True _fields = { "wizard_id": fields.Many2One("barcode.issue", "Wizard", required=True, on_delete="cascade"), "product_id": fields.Many2One("product", "Product", required=True), "qty": fields.Decimal("Qty", required=True), "uom_id": fields.Many2One("uom", "UoM", required=True), "qty2": fields.Decimal("Secondary Qty"), "lot_id": fields.Many2One("stock.lot", "Lot / Serial Number"), "container_from_id": fields.Many2One("stock.container", "From Container"), "container_to_id": fields.Many2One("stock.container", "To Container"), "location_from_id": fields.Many2One("stock.location", "From Location"), "location_to_id": fields.Many2One("stock.location", "To Location"), "related_id": fields.Reference([["sale.order", "Sales Order"], ["purchase.order", "Purchase Order"]], "Related To"), "qty2": fields.Decimal("Qty2"), "notes": fields.Text("Notes"), }
class ConvAccount(Model): _name = "conv.account" _transient = True _fields = { "conv_id": fields.Many2One("conv.bal", "Conversion", required=True), "account_id": fields.Many2One("account.account", "Account", required=True, on_delete="cascade"), "debit": fields.Decimal("Debit"), "credit": fields.Decimal("Credit"), "amount_cur": fields.Decimal("Currency Amt"), "track_id": fields.Many2One("account.track.categ", "Track-1", condition=[["type", "=", "1"]]), "track2_id": fields.Many2One("account.track.categ", "Track-2", condition=[["type", "=", "2"]]), }
class ProductionQC(Model): _name = "production.qc" _string = "Production Quality Control" _fields = { "order_id": fields.Many2One("production.order", "Production Order", required=True, on_delete="cascade"), "test_id": fields.Many2One("qc.test", "QC Test", required=True), "sample_qty": fields.Decimal("Sampling Qty"), "value": fields.Char("Value"), "min_value": fields.Decimal("Min Value", function="_get_related", function_context={"path": "test_id.min_value"}), "max_value": fields.Decimal("Max Value", function="_get_related", function_context={"path": "test_id.max_value"}), "result": fields.Selection([["yes", "Pass"], ["no", "Not Pass"], ["na", "N/A"]], "Result", required=True), } _defaults = { "result": "no", }
class PaySlipLine(Model): _name = "hr.payslip.line" _string = "Pay Slip Line" _fields = { "slip_id": fields.Many2One("hr.payslip", "Pay Slip", required=True, on_delete="cascade"), "sequence": fields.Integer("Sequence"), "payitem_id": fields.Many2One("hr.payitem", "Pay Item", required=True), "qty": fields.Decimal("Qty", required=True), "rate": fields.Decimal("Rate", required=True), "amount": fields.Decimal("Amount", function="get_amount"), "comments": fields.One2Many("message", "related_id", "Comments"), } _defaults = { "state": "draft", "date_from": lambda *a: date.today().strftime("%Y-%m-01"), "date_to": lambda *a: (date.today() + relativedelta(day=31)).strftime("%Y-%m-%d"), } _order = "sequence" def get_amount(self, ids, context={}): # TODO need some logic for compute pay item vals = {} for obj in self.browse(ids): vals[obj.id] = obj.qty * obj.rate return vals
class Reconcile(Model): _name = "account.reconcile" _string = "Account Reconciliation" _name_field = "number" _audit_log = True _fields = { "lines": fields.One2Many("account.move.line", "reconcile_id", "Account Entries", condition=[["move_id.state", "=", "posted"]]), "debit": fields.Decimal("Total Debit", function="get_total", function_multi=True), "credit": fields.Decimal("Total Credit", function="get_total", function_multi=True), "balance": fields.Decimal("Balance", function="get_total", function_multi=True), "number": fields.Char("Number", function="get_total", function_multi=True), } def get_total(self, ids, context={}): vals = {} for obj in self.browse(ids): debit = 0 credit = 0 for line in obj.lines: debit += line.debit credit += line.credit balance = debit - credit number = "R%d" % obj.id if balance != 0: number += "*" vals[obj.id] = { "debit": debit, "credit": credit, "balance": balance, "number": number, } return vals
class TaxRate(Model): _name = "hr.tax.rate" _fields = { "settings_id": fields.Many2One("hr.payroll.settings", "Settings", required=True), "sequence": fields.Integer("Step No."), "min_income": fields.Decimal("Min. Net Income"), "max_income": fields.Decimal("Max. Net Income"), "rate": fields.Decimal("Tax Rate"), } _order = "sequence" def compute_tax(self, income=0): total_tax = 0 total_base = 0 for obj in self.search_browse([]): if obj.min_income and income < obj.min_income: break base = min(income, obj.max_income) - total_base tax = base * (obj.rate or 0) / 100 total_tax += tax total_base += base return total_tax
class BarcodeIssueRMLine(Model): _name = "barcode.issue.rm.line" _transient = True _fields = { "wizard_id": fields.Many2One("barcode.issue.rm", "Wizard", required=True, on_delete="cascade"), "product_id": fields.Many2One("product", "Product", required=True), "qty": fields.Decimal("Qty Issued", required=True), "uom_id": fields.Many2One("uom", "UoM", required=True), "lot_id": fields.Many2One("stock.lot", "Lot / Serial Number"), "qty_stock": fields.Decimal("Qty In Stock", function="get_qty_stock"), } def get_qty_stock(self, ids, context={}): vals = {} for obj in self.browse(ids): wiz = obj.wizard_id loc_id = wiz.location_from_id.id if loc_id: res = get_model("stock.location").compute_balance( [loc_id], obj.product_id.id, lot_id=obj.lot_id.id) # XXX: speed qty = res["bal_qty"] else: qty = None vals[obj.id] = qty return vals
class ProductionPeriodCost(Model): _name = "production.period.cost" _string = "Production Period Cost" _fields = { "period_id": fields.Many2One("production.period", "Production Period", required=True, on_delete="cascade"), "product_id": fields.Many2One("product", "Cost Product"), "amount": fields.Decimal("Period Actual Amount", required=True), "alloc_amount": fields.Decimal("Production Order Amount", function="get_alloc_amount"), } def get_alloc_amount(self, ids, context={}): period_ids = [] for obj in self.browse(ids): period_ids.append(obj.period_id.id) period_ids = list(set(period_ids)) total_costs = {} for cost in get_model("production.cost").search_browse( [["order_id.period_id", "in", period_ids]]): period_id = cost.order_id.period_id.id prod_id = cost.product_id.id k = (period_id, prod_id) total_costs.setdefault(k, 0) total_costs[k] += cost.amount vals = {} for obj in self.browse(ids): k = (obj.period_id.id, obj.product_id.id) vals[obj.id] = total_costs.get(k, 0) return vals
class PartTemplate(Model): _name = "job.part.template" _string = "Part Template" _fields = { "job_template_id": fields.Many2One("job.template", "Job Template", required=True, on_delete="cascade"), "product_id": fields.Many2One("product", "Product"), "qty": fields.Decimal("Qty", required=True), "uom_id": fields.Many2One("uom", "UoM", required=True), "location_id": fields.Many2One("stock.location", "From Warehouse", required=True), "unit_price": fields.Decimal("Sale Unit Price"), "amount": fields.Decimal("Sale Amount", function="get_amount"), } def onchange_product(self, context={}): data = context["data"] prod_id = data["product_id"] prod = get_model("product").browse(prod_id) data["uom_id"] = prod.uom_id.id data["unit_price"] = prod.sale_price return data def get_amount(self, ids, context={}): vals = {} for obj in self.browse(ids): vals[obj.id] = (obj.qty or 0) * (obj.unit_price or 0) return vals
class JobLine(Model): _name = "job.line" _fields = { "job_id": fields.Many2One("job", "Job", required=True, on_delete="cascade"), "sequence": fields.Integer("Sequence"), "type": fields.Selection( [["labor", "Labor"], ["part", "Parts"], ["other", "Other"]], "Type"), "description": fields.Text("Description"), "product_id": fields.Many2One("product", "Product"), "qty": fields.Decimal("Qty"), "uom_id": fields.Many2One("uom", "UoM"), "unit_price": fields.Decimal("Sale Unit Price"), "amount": fields.Decimal("Sale Amount", function="get_amount"), "payment_type": fields.Selection([["contract", "Included In Contract"], ["job", "Not Included In Contract"]], "Payment Type"), } _order = "sequence,id" def get_amount(self, ids, context={}): vals = {} for obj in self.browse(ids): vals[obj.id] = (obj.qty or 0) * (obj.unit_price or 0) return vals
class Balance(Model): _name = "account.balance" _string = "Account Balance" _fields = { "account_id": fields.Many2One("account.account", "Account", required=True, on_delete="cascade"), "track_id": fields.Many2One("account.track.categ", "Track-1"), "debit": fields.Decimal("Debit", required=True), "credit": fields.Decimal("Credit", required=True), "amount_cur": fields.Decimal("Currency Amt"), } def update_balances(self, context={}): # XXX: make faster db = get_connection() res = db.query( "SELECT account_id,track_id,SUM(debit) AS total_debit,SUM(credit) AS total_credit,SUM(amount_cur) AS total_amount_cur FROM account_move_line GROUP BY account_id,track_id" ) bals = {} for r in res: bals[(r.account_id, r.track_id)] = (r.total_debit, r.total_credit, r.total_amount_cur) db.execute("DELETE FROM account_balance") for (acc_id, track_id), (debit, credit, amount_cur) in bals.items(): db.execute( "INSERT INTO account_balance (account_id,track_id,debit,credit,amount_cur) VALUES (%s,%s,%s,%s,%s)", acc_id, track_id, debit, credit, amount_cur)
class ProductionPeriod(Model): _name = "production.period" _string = "Production Period" _name_field = "number" _fields = { "number": fields.Char("Number", required=True, search=True), "date_from": fields.Date("Date From", required=True), "date_to": fields.Date("Date To", required=True), "production_orders": fields.One2Many("production.order", "period_id", "Production Orders"), "costs": fields.One2Many("production.period.cost", "period_id", "Period Costs"), "amount_total": fields.Decimal("Period Actual Total", function="get_total", function_multi=True), "alloc_total": fields.Decimal("Production Order Total", function="get_total", function_multi=True), } def update_period_costs(self, ids, context={}): obj = self.browse(ids)[0] cost_prod_ids = [] for cost in get_model("production.cost").search_browse( [["order_id.period_id", "=", obj.id]]): prod_id = cost.product_id.id cost_prod_ids.append(prod_id) cost_prod_ids = list(set(cost_prod_ids)) cur_prod_ids = [c.product_id.id for c in obj.costs] new_prod_ids = [ prod_id for prod_id in cost_prod_ids if prod_id not in cur_prod_ids ] for prod_id in new_prod_ids: vals = { "period_id": obj.id, "product_id": prod_id, "amount": 0, } get_model("production.period.cost").create(vals) def get_total(self, ids, context={}): vals = {} for obj in self.browse(ids): amt = 0 alloc = 0 for cost in obj.costs: amt += cost.amount or 0 alloc += cost.alloc_amount or 0 vals[obj.id] = { "amount_total": amt, "alloc_total": alloc, } return vals
class BarcodeReceiveMFGLine(Model): _name = "barcode.receive.mfg.line" _transient = True _fields = { "wizard_id": fields.Many2One("barcode.receive.mfg", "Wizard", required=True, on_delete="cascade"), "product_id": fields.Many2One("product", "Product", required=True), "qty": fields.Decimal("Actual Receive Qty", required=True), "uom_id": fields.Many2One("uom", "UoM", required=True), "qty2": fields.Decimal("Actual Receive Secondary Qty"), "lot_id": fields.Many2One("stock.lot", "Lot / Serial Number"), "qty_planned": fields.Decimal("Planned Receive Qty", function="get_qty_planned"), "container_from_id": fields.Many2One("stock.container", "From Container"), "container_to_id": fields.Many2One("stock.container", "To Container"), "qty_issued": fields.Decimal("Issued Qty", function="get_qty_issued"), } def get_qty_planned(self, ids, context={}): vals = {} for obj in self.browse(ids): order = obj.wizard_id.production_id qty = 0 if obj.product_id.id == order.product_id.id: qty = max(0, order.qty_planned - order.qty_received) else: for comp in order.components: if comp.product_id.id == obj.product_id.id: qty = max(0, comp.qty_issued - comp.qty_planned) break vals[obj.id] = qty return vals def get_qty_issued(self, ids, context={}): vals = {} for obj in self.browse(ids): order = obj.wizard_id.production_id qty = 0 if obj.product_id.id == order.product_id.id: qty = max(0, -order.qty_received) else: for comp in order.components: if comp.product_id.id == obj.product_id.id: qty = max(0, comp.qty_issued) break vals[obj.id] = qty return vals
class BankReconcile(Model): _name = "account.bank.reconcile" _string = "Bank Reconciliation" _name_field = "number" _fields = { "account_lines": fields.One2Many("account.move.line", "bank_reconcile_id", "Account Entries"), "statement_lines": fields.One2Many("account.statement.line", "bank_reconcile_id", "Statement Lines"), "total_account": fields.Decimal("Total Account", function="get_total", function_multi=True), "total_statement": fields.Decimal("Total Statement", function="get_total", function_multi=True), "number": fields.Char("Number", function="get_total", function_multi=True), } def get_total(self, ids, context={}): vals = {} for obj in self.browse(ids): total_account = 0 total_statement = 0 for line in obj.account_lines: total_account += line.debit - line.credit for line in obj.statement_lines: total_statement += line.received - line.spent number = "R%d" % obj.id if abs(total_account - total_statement) > 0: number += "*" vals[obj.id] = { "total_account": total_account, "total_statement": total_statement, "number": number, } return vals def delete(self, ids, **kw): st_line_ids = [] move_line_ids = [] for obj in self.browse(ids): for st_line in obj.statement_lines: st_line_ids.append(st_line.id) for move_line in obj.account_lines: move_line_ids.append(move_line.id) st_line_ids = list(set(st_line_ids)) move_line_ids = list(set(move_line_ids)) get_model("account.statement.line").write(st_line_ids, {"state": "not_reconciled"}) get_model("account.move.line").write(move_line_ids, {"state": "not_reconciled"}) super().delete(ids, **kw)
class SaleOrderPromotion(Model): _name = "sale.order.promotion" _fields = { "sale_id": fields.Many2One("sale.order", "Sales Order", required=True, on_delete="cascade"), "promotion_id": fields.Many2One("sale.promotion","Promotion",required=True), "product_id": fields.Many2One("product","Apply To Product"), "percent": fields.Decimal("Promotion Percent"), "amount": fields.Decimal("Promotion Amount"), } _order = "id"
class SaleCost(Model): _name = "sale.cost" _string = "Cost" _fields = { "sale_id": fields.Many2One("sale.order","Sales Order",required=True,on_delete="cascade"), "sequence": fields.Char("Apply To Item No."), "product_id": fields.Many2One("product","Cost Product"), "description": fields.Text("Description",required=True,search=True), "unit_price": fields.Decimal("Unit Price"), # XXX deprecated "list_price": fields.Decimal("Supplier List Price"), "purchase_price": fields.Decimal("Purchase Price"), "purchase_duty_percent": fields.Decimal("Import Duty (%)"), "purchase_ship_percent": fields.Decimal("Shipping Charge (%)"), "landed_cost": fields.Decimal("Landed Cost"), "qty": fields.Decimal("Qty"), "uom_id": fields.Many2One("uom","UoM"), # XXX deprecated "amount": fields.Decimal("Cost Amount",function="get_amount"), "currency_id": fields.Many2One("currency","Currency"), "currency_rate": fields.Decimal("Currency Rate"), # XXX: deprecated "supplier_id": fields.Many2One("contact","Supplier"), } def get_amount(self,ids,context={}): vals={} for obj in self.browse(ids): vals[obj.id]=(obj.qty or 0)*(obj.landed_cost or 0) return vals
class kaopopupline(Model): _name = "kao.popup.line" _transient = True _fields = { "product_id": fields.Many2One("product", "Product", search=True), "amount": fields.Integer("Amount"), "price": fields.Decimal("Price"), "total": fields.Decimal("Total"), "pop_id": fields.Many2One("kao.popup", "Lines", on_delete="cascade"), }
class CreditWizardLine(Model): _name = "account.credit.wizard.line" _transient = True _fields = { "wiz_id": fields.Many2One("account.credit.wizard", "Wizard", required=True, on_delete="cascade"), "move_line_id": fields.Many2One("account.move.line", "Account Entry", required=True, readonly=True, on_delete="cascade"), "move_id": fields.Many2One("account.move", "Journal Entry", required=True, readonly=True, on_delete="cascade"), "date": fields.Date("Date", readonly=True), "account_id": fields.Many2One("account.account", "Account", required=True, readonly=True, on_delete="cascade"), "amount_credit_remain": fields.Decimal("Outstanding Credit", readonly=True), "amount": fields.Decimal("Amount"), }
class TransformSource(Model): _name = "stock.transform.source" _string = "Transform Source" _fields = { "transform_id": fields.Many2One("stock.transform", "Transform", on_delete="cascade"), "product_id": fields.Many2One("product", "Product", required=True), "qty": fields.Decimal("Qty", required=True, scale=6), "qty2": fields.Decimal("Qty2"), "uom_id": fields.Many2One("uom", "UoM", required=True), "lot_id": fields.Many2One("stock.lot", "Lot / Serial Number"), "container_id": fields.Many2One("stock.container", "Container"), }
class QCTest(Model): _name = "qc.test" _string = "QC Test" _fields = { "name": fields.Char("Test Name", search=True, required=True), "description": fields.Text("Description"), "min_value": fields.Decimal("Minimum Value"), "max_value": fields.Decimal("Maximum Value"), "comments": fields.One2Many("message", "related_id", "Comments"), "documents": fields.One2Many("document", "related_id", "Documents"), } _order = "name"
class BomLine(Model): _name = "bom.line" _fields = { "bom_id": fields.Many2One("bom", "BoM", required=True, on_delete="cascade"), "product_id": fields.Many2One("product", "Product", required=True), "qty": fields.Decimal("Qty", required=True, scale=6), "uom_id": fields.Many2One("uom", "UoM", required=True), "location_id": fields.Many2One("stock.location", "RM Warehouse"), "container": fields.Selection([["sale", "From Sales Order"]], "RM Container"), "lot": fields.Selection([["production", "From Production Order"]], "RM Lot"), "issue_method": fields.Selection([["manual", "Manual"], ["backflush", "Backflush"]], "Issue Method"), "qty2": fields.Decimal("Qty2", scale=6), "notes": fields.Text("Notes"), }
class ConvSaleInvoice(Model): _name = "conv.sale.invoice" _transient = True _fields = { "conv_id": fields.Many2One("conv.bal", "Conversion", required=True), "number": fields.Char("Number", required=True), "ref": fields.Char("Reference"), "contact_id": fields.Many2One("contact", "Contact", required=True, on_delete="cascade"), "date": fields.Date("Date", required=True), "due_date": fields.Date("Due Date", required=True), "amount_due": fields.Decimal("Amount Due", required=True), "move_line_id": fields.Many2One("account.move.line", "Move Line"), "account_id": fields.Many2One("account.account", "Account", required=True), "amount_cur": fields.Decimal("Currency Amt"), }
class Packaging(Model): _name = "stock.packaging" _string = "Packaging" _fields = { "name": fields.Char("Name", required=True), "code": fields.Char("Code"), "description": fields.Text("Description"), "width": fields.Decimal("Width"), "height": fields.Decimal("Height"), "length": fields.Decimal("Length"), "weight": fields.Decimal("Weight"), "comments": fields.One2Many("message", "related_id", "Comments"), "product_id": fields.Many2One("product", "Product"), } _order = "name"
class BarcodeValidateLine(Model): _name = "barcode.validate.line" _transient = True _fields = { "wizard_id": fields.Many2One("barcode.validate", "Wizard", required=True, on_delete="cascade"), "product_id": fields.Many2One("product", "Product", required=True), "qty_planned": fields.Decimal("Planned Qty", required=True, readonly=True), "qty_actual": fields.Decimal("Validated Qty"), "uom_id": fields.Many2One("uom", "UoM", required=True), "lot_id": fields.Many2One("stock.lot", "Lot / Serial Number"), "container_to_id": fields.Many2One("stock.container", "Container"), "location_from_id": fields.Many2One("stock.location", "From Location"), "location_to_id": fields.Many2One("stock.location", "To Location"), "related_id": fields.Reference([["sale.order", "Sales Order"], ["purchase.order", "Purchase Order"], ["job", "Service Order"], ["product.claim", "Claim Bill"], ["product.borrow", "Borrow Request"], ["stock.picking", "Picking"]], "Related To"), }
class JobPart(Model): _name = "job.part" _audit_log = True _fields = { "job_id": fields.Many2One("job", "Job", required=True, on_delete="cascade"), "product_id": fields.Many2One("product", "Product", required=True), "qty_planned": fields.Decimal("Planned Qty", required=True), "uom_id": fields.Many2One("uom", "UoM", required=True), "location_id": fields.Many2One("stock.location", "From Warehouse", required=True), "qty_issued": fields.Decimal("Issued Qty", function="get_qty_issued"), "unit_price": fields.Decimal("Sale Unit Price"), "amount": fields.Decimal("Sale Amount", function="get_amount"), } def get_amount(self, ids, context={}): vals = {} for obj in self.browse(ids): if obj.qty_issued and obj.unit_price: vals[obj.id] = obj.qty_issued * obj.unit_price else: vals[obj.id] = None return vals def get_qty_issued(self, ids, context={}): vals = {} for obj in self.browse(ids): job = obj.job_id total_qty = 0 for pick in job.pickings: for move in pick.lines: if move.product_id.id != obj.product_id.id or move.state != "done": continue qty = get_model("uom").convert(move.qty, move.uom_id.id, obj.uom_id.id) if move.location_from_id.id == obj.location_id.id and move.location_to_id.id != obj.location_id.id: total_qty += qty elif move.location_from_id.id != obj.location_id.id and move.location_to_id.id == obj.location_id.id: total_qty -= qty vals[obj.id] = total_qty return vals
class TrackEntry(Model): _name = "account.track.entry" _string = "Tracking Entries" _fields = { "track_id": fields.Many2One("account.track.categ", "Tracking Category",required=True,on_delete="cascade",search=True), "date": fields.Date("Date",required=True,search=True), "amount": fields.Decimal("Amount",required=True), "product_id": fields.Many2One("product","Product",search=True), "description": fields.Text("Description"), "qty": fields.Decimal("Qty"), "uom_id": fields.Many2One("uom","UoM"), "unit_price": fields.Decimal("Unit Price"), "related_id": fields.Reference([["account.invoice","Invoice"],["stock.picking","Stock Picking"],["work.time","Work Time"],["hr.expense","Expense Claim"]],"Related To"), "move_id": fields.Many2One("account.move","Journal Entry",search=True), } _order = "date desc,id desc" _defaults={ "date": lambda *a: time.strftime("%Y-%m-%d"), } def onchange_product(self,context={}): data=context.get("data",{}) print("#"*80) print("ID",data.get("id")) prod_id=data["product_id"] if not prod_id: return prod=get_model("product").browse(prod_id) price=prod.cost_price if prod.cost_method == "standard" else prod.landed_cost if not price: raise Exception("Missing Cost Price or Landed Cost") track_id=data["track_id"] track=get_model("account.track.categ").browse(track_id) if track.currency_id: settings=get_model("settings").browse(1) price=get_model("currency").convert(price,settings.currency_id.id,track.currency_id.id) data["unit_price"]=-price data["qty"]=1 data["uom_id"]=prod.uom_id.id data["amount"]=data["unit_price"] return data def update_amount(self,context={}): data=context.get("data",{}) unit_price=data.get("unit_price",0) qty=data.get("qty",0) data["amount"]=unit_price*qty return data
class BatchImportSaleInvoice(Model): _name = "batch.import.sale.invoice" _fields = { "import_id": fields.Many2One("batch.import", "Import", required=True, on_delete="cascade"), "date": fields.Date("Date", required=True), "number": fields.Text("Invoice No."), "contact": fields.Char("Customer Name"), "description": fields.Text("Description"), "amount": fields.Decimal("Amount"), "account_id": fields.Many2One("account.account", "Income Account"), "tax_id": fields.Many2One("account.tax.rate", "Tax Rate"), "invoice_id": fields.Many2One("account.invoice", "Invoice"), }