# -*- coding: utf-8 -*- from openerp import models, fields, api class AccountInvoice(models.Model): _inherit = 'account.invoice' ############################################################ # ACCOUNT INVOICE ############################################################ @api.model def getAccountInvoice(self,domain): AccountInvoice = self.env['account.invoice'].search(domain) decimal_precision = self.env['decimal.precision'].precision_get('Account') values = [] for invoice in AccountInvoice: values.append({ 'id': invoice.id, 'type': invoice.type, 'state': invoice.state, 'number': invoice.number, 'journal_id': [ invoice.journal_id.id, invoice.journal_id.name ], 'journal_type': invoice.journal_id.type, 'invoice_currency': [ invoice.currency_id.id, invoice.currency_id.name, invoice.currency_id.rate ], 'company_currency': [ invoice.company_id.currency_id.id, invoice.company_id.currency_id.name, invoice.company_id.currency_id.rate ], 'date_invoice': invoice.date_invoice, 'partner_id': [ invoice.partner_id.id, invoice.partner_id.name, invoice.partner_id.ruc, ], 'partner_info': { 'mobile': invoice.partner_id.mobile, 'phone': invoice.partner_id.phone, }, 'supplier_invoice_number': invoice.supplier_invoice_number, 'user_id': [ invoice.user_id.id, invoice.user_id.name ], 'period_id': [ invoice.period_id.id, invoice.period_id.name ], 'amount_untaxed': invoice.amount_untaxed, 'origin': invoice.origin, 'residual': invoice.residual, 'amount_tax': invoice.amount_tax, 'amount_total': invoice.amount_total, 'amount_untaxed_currency': invoice.amount_untaxed * (invoice.company_id.currency_id.rate / invoice.currency_id.rate), 'residual_currency': invoice.residual * (invoice.company_id.currency_id.rate / invoice.currency_id.rate), 'amount_tax_currency': invoice.amount_tax * (invoice.company_id.currency_id.rate / invoice.currency_id.rate), 'amount_total_currency': invoice.amount_total * (invoice.company_id.currency_id.rate / invoice.currency_id.rate), }) return values ############################################################ # POS ORDER ############################################################ @api.model def getPosOrder(self,domain): PosOrder = self.env['pos.order'].search(domain) decimal_precision = self.env['decimal.precision'].precision_get('Account') values = [] for order in PosOrder: values.append({ 'id': order.id, 'name': order.name, 'date_order': order.date_order, 'pricelist_id':[ order.pricelist_id.id, order.pricelist_id.name, ], 'sale_journal':[ order.sale_journal.id, order.sale_journal.name, ], 'partner_id': [ order.partner_id.id, order.partner_id.name, order.partner_id.ruc, ], 'user_id': [ order.user_id.id, order.user_id.name ], 'session_id': [ order.session_id.id, order.session_id.name ], 'order_currency': [ order.pricelist_id.currency_id.id, order.pricelist_id.currency_id.name, order.pricelist_id.currency_id.rate ], 'company_currency': [ order.company_id.currency_id.id, order.company_id.currency_id.name, order.company_id.currency_id.rate ], 'amount_tax': order.amount_tax, 'amount_total': order.amount_total, 'amount_tax_currency': order.amount_tax * (order.company_id.currency_id.rate / order.pricelist_id.currency_id.rate), 'amount_total_currency': order.amount_total * (order.company_id.currency_id.rate / order.pricelist_id.currency_id.rate), }) return values class AccountInvoiceLine(models.Model): _inherit = 'account.invoice.line' ############################################################ # ACCOUNT INVOICE LINE ############################################################ @api.model def getAccountInvoiceLine(self,domain): AccountInvoiceLine = self.env['account.invoice.line'].search(domain) decimal_precision = self.env['decimal.precision'].precision_get('Account') values = [] for line in AccountInvoiceLine: values.append({ 'id': line.id, 'invoice_id':line.invoice_id.id, 'number':line.invoice_id.number, 'supplier_invoice_number':line.invoice_id.supplier_invoice_number, 'date_invoice': line.invoice_id.date_invoice, 'user_id': [ line.invoice_id.user_id.id, line.invoice_id.user_id.name, ], 'partner_id': [ line.invoice_id.partner_id.id, line.invoice_id.partner_id.name, line.invoice_id.partner_id.ruc, ], 'store_id': [ line.invoice_id.journal_id.store_ids.id, line.invoice_id.journal_id.store_ids.name, ], 'period_id': [ line.invoice_id.period_id.id, line.invoice_id.period_id.name, ], 'journal_id': [ line.invoice_id.journal_id.id, line.invoice_id.journal_id.name, ], 'invoice_state': line.invoice_id.state, 'journal_type': line.invoice_id.journal_id.type, 'invoice_type': line.invoice_id.type, 'product_id': [ line.product_id.id, line.product_id.display_name, line.product_id.categ_id.complete_name, line.product_id.standard_price, ], 'product_category_id': line.product_id.categ_id.id, 'price_unit': line.price_unit, 'price_subtotal': line.price_subtotal, 'quantity': line.quantity, 'company_currency':[ line.invoice_id.company_id.currency_id.id, line.invoice_id.company_id.currency_id.name, line.invoice_id.company_id.currency_id.rate, ], 'invoice_currency':[ line.invoice_id.currency_id.id, line.invoice_id.currency_id.name, line.invoice_id.currency_id.rate, ], 'price_unit_currency': round(line.price_unit * (line.invoice_id.company_id.currency_id.rate / line.invoice_id.currency_id.rate),decimal_precision), 'price_subtotal_currency': round(line.price_subtotal * (line.invoice_id.company_id.currency_id.rate / line.invoice_id.currency_id.rate),decimal_precision), 'tax_currency': round((line.price_unit * (line.invoice_id.company_id.currency_id.rate / line.invoice_id.currency_id.rate) * line.quantity) - line.price_subtotal * (line.invoice_id.company_id.currency_id.rate / line.invoice_id.currency_id.rate),decimal_precision), 'amount_currency': round((line.quantity * line.price_unit) * (line.invoice_id.company_id.currency_id.rate / line.invoice_id.currency_id.rate),decimal_precision), }) return values ############################################################ # POS ORDER LINE ############################################################ @api.model def getPosOrderLine(self,domain): PosOrderLine = self.env['pos.order.line'].search(domain) decimal_precision = self.env['decimal.precision'].precision_get('Account') values = [] for line in PosOrderLine: values.append({ 'id': line.id, 'order_id': [ line.order_id.id, line.order_id.name ], 'product_id': [ line.product_id.id, line.product_id.display_name, line.product_id.standard_price, ], 'store_id': [ line.order_id.sale_journal.store_ids.id, line.order_id.sale_journal.store_ids.name, ], 'sale_journal': [ line.order_id.sale_journal.id, line.order_id.sale_journal.name, ], 'qty': line.qty, 'create_date': line.create_date, 'user_id': [ line.order_id.user_id.id, line.order_id.user_id.name ], 'partner_id': [ line.order_id.partner_id.id, line.order_id.partner_id.name, ], 'company_currency':[ line.order_id.company_id.currency_id.id, line.order_id.company_id.currency_id.name, line.order_id.company_id.currency_id.rate, ], 'order_currency':[ line.order_id.pricelist_id.currency_id.id, line.order_id.pricelist_id.currency_id.name, line.order_id.pricelist_id.currency_id.rate, ], 'price_unit': line.price_unit, 'price_subtotal': line.price_subtotal, 'price_subtotal_incl': line.price_subtotal_incl, 'price_unit_currency': round(line.price_unit * (line.order_id.company_id.currency_id.rate / line.order_id.pricelist_id.currency_id.rate),decimal_precision), 'price_subtotal_currency': round(line.price_subtotal * (line.order_id.company_id.currency_id.rate / line.order_id.pricelist_id.currency_id.rate),decimal_precision), 'price_subtotal_incl_currency': round(line.price_subtotal_incl * (line.order_id.company_id.currency_id.rate / line.order_id.pricelist_id.currency_id.rate),decimal_precision), # 'amount_currency': round(line.price_subtotal_incl * (line.order_id.company_id.currency_id.rate / line.order_id.pricelist_id.currency_id.rate),decimal_precision) }) return values class AccountJournal(models.Model): _inherit = 'account.journal' @api.model def getAccountJournal(self,domain): AccountJournal = self.env['account.journal'].search(domain) values = [] for journal in AccountJournal: if(journal.currency): complete_name = journal.name + ' (' + journal.currency.local_name + ')' else: complete_name = journal.name + ' (' + journal.company_id.currency_id.local_name + ')' values.append({ 'id': journal.id, 'name': journal.name, 'complete_name': complete_name, 'type': journal.type, 'store_ids': [ journal.store_ids.id, journal.store_ids.name, ], 'company_id': [ journal.company_id.id, journal.company_id.name ], 'currency': [ journal.currency.id, journal.currency.name ], }) return values class AccountBankStatementLine(models.Model): _inherit = 'account.bank.statement.line' @api.model def getAccountBankStatementLine(self,domain): AccountBankStatementLine = self.env['account.bank.statement.line'].search(domain) decimal_precision = self.env['decimal.precision'].precision_get('Account') values = [] for line in AccountBankStatementLine: try: pos_statement_id = line.pos_statement_id.id partner_id = [line.partner_id.id,line.partner_id.name] except: pos_statement_id = '' partner_id = '' if(line.journal_id.currency): amount_currency = round(line.amount * (line.company_id.currency_id.rate / line.journal_id.currency.rate),decimal_precision), else: amount_currency = line.amount values.append({ 'id': line.id, 'name': line.name, 'date': line.date, 'partner_id': partner_id, 'ref': line.ref, 'currency_id': [ line.currency_id.id, line.currency_id.name, ], 'journal_id': [ line.journal_id.id, line.journal_id.name, ], 'pos_statement_id': pos_statement_id, 'amount': line.amount, 'amount': line.amount_currency, 'amount_currency': amount_currency }) return values class AccountMoveLine(models.Model): _inherit = 'account.move.line' @api.model def getAccountMoveLine(self,domain): AccountMoveLine = self.env['account.move.line'].search(domain) decimal_precision = self.env['decimal.precision'].precision_get('Account') values = [] for line in AccountMoveLine: values.append({ 'id': line.id, 'name': line.name, 'date': line.date, 'date_maturity': line.date_maturity, 'reconcile_ref': line.reconcile_ref, 'amount_residual': line.amount_residual, 'partner_id': [ line.partner_id.id, line.partner_id.name, ], 'move_id': [ line.move_id.id, line.move_id.name, ], 'account_id': [ line.account_id.id, line.account_id.name, ], 'journal_id': [ line.journal_id.id, line.journal_id.name, ], 'debit': line.debit, 'credit': line.credit, }) return values class AccountAccount(models.Model): _inherit = 'account.account' @api.model def getAccountAccount(self,domain): AccountAccount = self.env['account.account'].search(domain) values = [] for account in AccountAccount: values.append({ 'id': account.id, 'name': account.name, }) return values class ResCompany(models.Model): _inherit = 'res.company' @api.model def getResCompany(self,domain): ResCompany = self.env['res.company'].search(domain) values = [] for company in ResCompany: values.append({ 'id': company.id, 'name': company.name, 'currency_id': [ company.currency_id.id, company.currency_id.name, ], 'company_ruc': company.partner_id.ruc, 'phone': company.phone, 'logo': company.logo, }) return values class AccountVoucher(models.Model): _inherit = 'account.voucher' @api.model def getAccountVoucher(self,domain): AccountVoucher = self.env['account.voucher'].search(domain) values = [] for voucher in AccountVoucher: values.append({ 'id': voucher.id, 'number': voucher.number, 'create_uid': voucher.create_uid.name, 'partner_id': [ voucher.partner_id.id, voucher.partner_id.name, ], 'journal_id': [ voucher.journal_id.id, voucher.journal_id.name, ], 'period_id': [ voucher.period_id.id, voucher.period_id.name, ], 'currency_id': [ voucher.currency_id.id, voucher.currency_id.name, ], 'reference': voucher.reference, 'date': voucher.date, 'amount': voucher.amount, 'amount_currency': voucher.amount * (voucher.company_id.currency_id.rate / voucher.currency_id.rate), }) return values class ResCurrency(models.Model): _inherit = 'res.currency' @api.model def getResCurrency(self,domain): ResCurrency = self.env['res.currency'].search(domain) values = [] for currency in ResCurrency: values.append({ 'id': currency.id, 'name': currency.name, 'symbol': currency.symbol, 'rate_silent': currency.rate_silent, 'base': currency.base, 'decimal_separator': currency.decimal_separator, 'decimal_places': currency.decimal_places, 'thousands_separator': currency.thousands_separator, 'symbol_position': currency.symbol_position, }) return values class ResPartner(models.Model): _inherit = 'res.partner' @api.model def getResPartnerSmile(self,domain): ResPartner = self.env['res.partner'].search(domain) values = [] for partner in ResPartner: values.append({ 'id': partner.id, 'name': partner.name, 'ruc': partner.ruc, 'street': partner.street, 'city': partner.city, 'phone': partner.phone, 'mobile': partner.mobile, 'email': partner.email, 'property_product_pricelist': partner.property_product_pricelist.name, 'property_product_pricelist_purchase': partner.property_product_pricelist_purchase.name, 'credit': partner.credit, 'debit': partner.debit, 'supplier': partner.supplier, 'is_medic': partner.is_medic, 'medic': [ partner.medic.id, partner.medic.name, ], }) return values class ProductProduct(models.Model): _inherit = 'product.product' ############################################################ # PRODUCT PRODUCT ############################################################ @api.model def getProductProduct(self,domain): ProductProduct = self.env['product.product'].search(domain) values = [] for product in ProductProduct: attributeValuesLines = map(lambda x: x.id, product.attribute_value_ids) attributeIDS = [] for arttIds in self.env['product.attribute.value'].search([('id', 'in', attributeValuesLines)]): attributeIDS.append(arttIds.attribute_id.id) try: # sale list price sale_price = map(lambda x: x.id, product.pricelists) saleIDS = [] for item in self.env['product.pricelist'].search([('id', 'in', sale_price)]): saleIDS.append(item.id) # purchase list price buy_price = map(lambda x: x.id, product.purchase_pricelists) buyIDS = [] for item in self.env['product.pricelist'].search([('id', 'in', buy_price)]): buyIDS.append(item.id) except: buyIDS = [] saleIDS = [] try: brand = product.product_brand_id.id except: brand = '' values.append({ 'id': product.id, 'name': product.name, 'display_name': product.display_name, 'standard_price': product.standard_price, 'lst_price': product.lst_price, 'categ_id': { 'id': product.categ_id.id, 'name': product.categ_id.name, 'complete_name': product.categ_id.complete_name, }, 'product_brand_id':brand, 'atribute_value_ids': attributeValuesLines, 'attribute_ids': attributeIDS, 'qty_available': product.qty_available, 'default_code': product.default_code, 'image_medium': product.image_medium, 'pricelists': saleIDS, 'purchase_pricelists':buyIDS, 'product_tmpl_id': product.product_tmpl_id.id, 'image': product.image, 'ean13': product.ean13, }) return values ############################################################ # PRODUCT PRODUCT - STOCK 'minimo_quantity': product.minimo_quantity, ############################################################ @api.model def getProductProductStock(self,domain): ProductProduct = self.env['product.product'].search(domain) values = [] for product in ProductProduct: attributeValuesLines = map(lambda x: x.id, product.attribute_value_ids) attributeIDS = [] for arttIds in self.env['product.attribute.value'].search([('id', 'in', attributeValuesLines)]): attributeIDS.append(arttIds.attribute_id.id) values.append({ 'id': product.id, 'display_name': product.display_name, 'standard_price': product.standard_price, 'lst_price': product.lst_price, 'categ_id': { 'id': product.categ_id.id, 'name': product.categ_id.name, 'complete_name': product.categ_id.complete_name, }, 'atribute_value_ids': attributeValuesLines, 'attribute_ids': attributeIDS, 'default_code': product.default_code, 'ean13': product.ean13, }) return values ############################################################ # PRODUCT BRAND ############################################################ @api.model def getProductBrand(self,domain): ProductBrand = self.env['product.brand'].search(domain) values = [] for brand in ProductBrand: values.append({ 'id': brand.id, 'name': brand.name, }) return values class ProductCategory(models.Model): _inherit = 'product.category' @api.model def getProductCategory(self,domain): ProductCategory = self.env['product.category'].search(domain) values = [] for category in ProductCategory: values.append({ 'id': category.id, 'name': category.name, 'display_name': category.display_name, 'parent_id': [ category.parent_id.id, category.parent_id.name, ], }) return values class ProductAttribute(models.Model): _inherit = 'product.attribute' @api.model def getProductAttribute(self,domain): ProductAttribute = self.env['product.attribute'].search(domain) values = [] for attribute in ProductAttribute: values.append({ 'id': attribute.id, 'name': attribute.name, }) return values class ProductAttributeValue(models.Model): _inherit = 'product.attribute.value' @api.model def getProductAttributeValue(self,domain): ProductAttributeValue = self.env['product.attribute.value'].search(domain) values = [] for value in ProductAttributeValue: values.append({ 'id': value.id, 'name': value.name, 'attribute_id': [ value.attribute_id.id, value.attribute_id.name, ], }) return values class StockLocation(models.Model): _inherit = 'stock.location' @api.model def getStockLocation(self,domain): StockLocation = self.env['stock.location'].search(domain) values = [] for location in StockLocation: values.append({ 'id': location.id, 'name': location.name, 'display_name': location.display_name, 'parent_name': location.location_id.name, 'company_id': [ location.company_id.id, location.company_id.name, ], 'store_id': [ location.store_id.id, location.store_id.name, ], 'usage': location.usage, }) return values class StockQuant(models.Model): _inherit = 'stock.quant' @api.model def getStockQuant(self,domain): StockQuant = self.env['stock.quant'].search(domain) values = [] for quant in StockQuant: values.append({ 'id': quant.id, 'name': quant.name, 'display_name': quant.display_name, 'location_id': [ quant.location_id.id, quant.location_id.name, ], 'product_id': [ quant.product_id.id, quant.product_id.name, ], 'qty': quant.qty, }) return values class StockMove(models.Model): _inherit = 'stock.move' @api.model def getStockMove(self,domain): StockMove = self.env['stock.move'].search(domain) values = [] for move in StockMove: values.append({ 'id': move.id, 'create_date' : move.create_date, 'name': move.name, 'state' : move.state, 'location_id': { 'id' : move.location_id.id, 'complete_name' : move.location_id.complete_name, 'store_id' : move.location_id.store_id.id, }, 'location_dest_id': { 'id' : move.location_dest_id.id, 'complete_name' : move.location_dest_id.complete_name, 'store_id' : move.location_dest_id.store_id.id, }, 'origin' : move.origin, 'picking_id' : { 'id' : move.picking_id.id, 'name' : move.picking_id.name, }, 'partner_id' : { 'id' : move.partner_id.id, 'name' : move.partner_id.name, }, 'product_id': { 'id' : move.product_id.id, 'display_name' : move.product_id.display_name, }, 'product_uom_qty': move.product_uom_qty, }) return values class StockPicking(models.Model): _inherit = 'stock.picking' @api.model def getStockPicking(self,domain): StockPicking = self.env['stock.picking'].search(domain) values = [] for picking in StockPicking: values.append({ 'id' : picking.id, 'date' : picking.create_date, 'name' : picking.name, 'state' : picking.state, 'partner_id' : { 'id' : picking.partner_id.id, 'name' : picking.partner_id.name, }, 'move_type' : picking.move_type, 'picking_type_id' : { 'id' : picking.picking_type_id.id, 'name' : picking.picking_type_id.name, }, 'date_done' : picking.date_done, 'priority' : picking.priority, }) return values class ProductPriceList(models.Model): _inherit = 'product.pricelist' @api.model def getProductPriceList(self,domain): ProductPriceList = self.env['product.pricelist'].search(domain) values = [] for pricelist in ProductPriceList: version_ids = map(lambda x: x.id, pricelist.version_id) versionIDS = [] for item in self.env['product.pricelist'].search([('id', 'in', version_ids)]): versionIDS.append(item.id) values.append({ 'id' : pricelist.id, 'name' : pricelist.name, 'type' : pricelist.type, 'version_id' : versionIDS, 'store_id' : { 'id' : pricelist.store_id.id, 'name' : pricelist.store_id.name, }, 'currency_id' : { 'id' : pricelist.currency_id.id, 'name' : pricelist.currency_id.name, 'rate_silent': pricelist.currency_id.rate_silent, }, }) return values