class PriceList(dbmix(NPriceList, price_override_name)): @classmethod def deserialize(cls, dict_input): prod = super(cls, PriceList).deserialize(dict_input) if prod.multiplicador: prod.multiplicador = Decimal(prod.multiplicador) return prod
class Client(dbmix(NCliente)): @property def fullname(self): nombres = self.nombres if not nombres: nombres = '' apellidos = self.apellidos if not apellidos: apellidos = '' return apellidos + ' ' + nombres
class AccountTransaction(dbmix(NAccountTransaction)): SALE = 'sales' SPENT = 'spents' CUSTOMER_PAYMENT = 'payments' CUSTOMER_PAYMENT_CHECK = 'payment_check' CUSTOMER_PAYMENT_DEPOSIT = 'payment_deposit' TURNED_IN = 'turned_in' def serialize(self): result = super(AccountTransaction, self).serialize() if hasattr(self, 'img'): result['img'] = self.img return result
def test_dbmix(self): Base = declarative_base() class TestModel(Base): __tablename__ = 'test' key = Column(Integer, primary_key=True) value = Column(Integer) Wrapped = dbmix(TestModel) x = Wrapped() x.key = 1 x.value = 2 y = x.db_instance() self.assertEquals(type(y), TestModel) self.assertEquals(1, y.key) self.assertEquals(2, x.value) serialized = x.serialize() self.assertEquals({'key': 1, 'value': 2}, serialized)
import os import uuid from sqlalchemy import desc from henry.base.dbapi import dbmix from henry.base.serialization import SerializableMixin from henry.invoice.dao import PaymentFormat from .acct_schema import (NBank, NDepositAccount, NPayment, NCheck, NDeposit, NImage, NComment, NAccountStat, NSpent, NAccountTransaction) from henry.schema.legacy import NTodo Todo = dbmix(NTodo) Comment = dbmix(NComment) Image = dbmix(NImage) Bank = dbmix(NBank) DepositAccount = dbmix(NDepositAccount) AccountStat = dbmix(NAccountStat) Spent = dbmix(NSpent) class Payment(SerializableMixin): _name = ( 'uid', 'note_id', 'client_id', 'value', 'date', 'type', 'deleted', )
from henry.base.dbapi import dbmix from henry.users.schema import NUsuario, NCliente __author__ = 'han' User = dbmix(NUsuario) class Client(dbmix(NCliente)): @property def fullname(self): nombres = self.nombres if not nombres: nombres = '' apellidos = self.apellidos if not apellidos: apellidos = '' return apellidos + ' ' + nombres
class ProdItemGroup(dbmix(NItemGroup)): def merge_from(self, the_dict): super(ProdItemGroup, self).merge_from(the_dict) self.base_price_usd = convert_decimal(self.base_price_usd, 0) return self
class Inventory(dbmix(NInventory)): def merge_from(self, the_dict): super(Inventory, self).merge_from(the_dict) self.quantity = convert_decimal(self.quantity, 0) return self
class ProdItem(dbmix(NItem)): def merge_from(self, the_dict): super(ProdItem, self).merge_from(the_dict) self.multiplier = convert_decimal(self.multiplier, 1) return self
from decimal import Decimal import datetime from henry.base.dbapi import dbmix from henry.dao.transaction import Transaction from henry.product.schema import NInventoryRevision, NInventoryRevisionItem from .schema import (NBodega, NProducto, NContenido, NCategory, NInventory, NPriceListLabel, NPriceList, NItemGroup, NItem, NStore) Bodega = dbmix(NBodega) Product = dbmix(NProducto) ProdCount = dbmix(NContenido) Category = dbmix(NCategory) PriceListLabel = dbmix(NPriceListLabel) Store = dbmix(NStore) def convert_decimal(x, default=None): return default if x is None else Decimal(x) price_override_name = (('prod_id', 'codigo'), ('cant_mayorista', 'threshold')) class PriceList(dbmix(NPriceList, price_override_name)): @classmethod def deserialize(cls, dict_input): prod = super(cls, PriceList).deserialize(dict_input) if prod.multiplicador: prod.multiplicador = Decimal(prod.multiplicador) return prod class ProdItem(dbmix(NItem)): def merge_from(self, the_dict):
from decimal import Decimal from sqlalchemy import func from henry.dao.document import Status from henry.base.dbapi import dbmix from henry.base.serialization import parse_iso_datetime, TypedSerializableMixin, json_dumps from henry.product.dao import ProdItemGroup, InventoryMovement from .schema import NInventory, NSale, NInvMovementMeta, NEntity __author__ = 'han' Inventory = dbmix(NInventory) Entity = dbmix(NEntity) def client_sale_report(dbapi, start, end): sales_by_date = list(dbapi.db_session.query( NSale.seller_ruc, func.date(NSale.timestamp), func.sum(NSale.pretax_amount_usd), func.sum(NSale.tax_usd), func.count(NSale.uid)).filter( NSale.timestamp >= start, NSale.timestamp <= end, NSale.status == Status.NEW, NSale.payment_format != 'None').group_by( func.date(NSale.timestamp), NSale.seller_ruc)) for ruc, date, sale, tax, count in sales_by_date: yield SaleReportByDate( timestamp=date, ruc=ruc, sale_pretax_usd=sale, tax_usd=tax, count=count ) class InvMovementMeta(dbmix(NInvMovementMeta)): def merge_from(self, other):
import os import uuid from sqlalchemy import desc from henry.base.dbapi import dbmix from henry.base.serialization import SerializableMixin from henry.invoice.dao import PaymentFormat from .acct_schema import (NBank, NDepositAccount, NPayment, NCheck, NDeposit, NImage, NComment, NTodo, NAccountStat, NSpent, NAccountTransaction) Todo = dbmix(NTodo) Comment = dbmix(NComment) Image = dbmix(NImage) Bank = dbmix(NBank) DepositAccount = dbmix(NDepositAccount) AccountStat = dbmix(NAccountStat) Spent = dbmix(NSpent) class Payment(SerializableMixin): _name = ( 'uid', 'note_id', 'client_id', 'value', 'date', 'type', 'deleted', )
from decimal import Decimal from henry.base.dbapi import dbmix from henry.base.serialization import SerializableMixin, TypedSerializableMixin, parse_iso_datetime, json_dumps from henry.dao.document import Status from henry.product.dao import ProdItemGroup, InventoryMovement from sqlalchemy import func from .schema import (NUniversalProduct, NDeclaredGood, NPurchaseItem, NPurchase, NSale, NInvMovementMeta, NEntity, NInventory) UniversalProd = dbmix(NUniversalProduct) DeclaredGood = dbmix(NDeclaredGood) PurchaseItem = dbmix(NPurchaseItem) class Purchase(dbmix(NPurchase)): @classmethod def deserialize(cls, thedict): result = super(Purchase, cls).deserialize(thedict) if thedict.get('total_gross_weight_kg', None): result.total_gross_weight_kg = Decimal(result.total_gross_weight_kg) if thedict.get('total_rmb', None): result.total_rmb = result.total_rmb if thedict.get('timestamp', None): result.timestamp = parse_iso_datetime(result.timestamp) return result class PurchaseFull(SerializableMixin): _name = ('meta', 'items')
equiv_multiplier='100', type=Unit.UNIT), 'p200ge': Unit(uid='p200ge', name_zh=u'200粒一包', name_es='paquete de 200', equiv_base='ge', equiv_multiplier='200', type=Unit.UNIT), 'p500ge': Unit(uid='p500ge', name_zh=u'500粒一包', name_es='paquete de 500', equiv_base='ge', equiv_multiplier='500', type=Unit.UNIT), 'p1000ge': Unit(uid='p1000ge', name_zh=u'1000粒一包', name_es='paquete de 1000', equiv_base='ge', equiv_multiplier='1000', type=Unit.UNIT), 'p2000ge': Unit(uid='p2000ge', name_zh=u'2000粒一包', name_es='paquete de 2000', equiv_base='ge', equiv_multiplier='2000', type=Unit.UNIT), 'p5000ge': Unit(uid='p5000ge', name_zh=u'5000粒一包', name_es='paquete de 5000', equiv_base='ge', equiv_multiplier='5000', type=Unit.UNIT), 'doz': Unit(uid='doz', name_zh=u'打', name_es='docena', equiv_base='ge', equiv_multiplier='12', type=Unit.UNIT), } UniversalProd = dbmix(NUniversalProduct) DeclaredGood = dbmix(NDeclaredGood) class PurchaseItem(dbmix(NPurchaseItem)): @classmethod def deserialize(cls, thedict): result = super(PurchaseItem, cls).deserialize(thedict) if thedict.get('box', None): result.box = Decimal(result.box) if thedict.get('box') == '': result.box = None if thedict.get('price_rmb', None): result.price_rmb = Decimal(result.price_rmb) if thedict.get('quantity', None): result.quantity = Decimal(result.quantity)
from collections import defaultdict from decimal import Decimal import datetime import functools import json import os from henry.base.dbapi import dbmix from henry.base.serialization import (json_dumps, parse_iso_datetime, parse_iso_date, TypedSerializableMixin) from .schema import NInventoryRevision, NInventoryRevisionItem from .schema import (NBodega, NCategory, NPriceListLabel, NPriceList, NItemGroup, NItem, NStore, NProdTag, NProdTagContent) Bodega = dbmix(NBodega) Category = dbmix(NCategory) PriceListLabel = dbmix(NPriceListLabel) Store = dbmix(NStore) ProdTag = dbmix(NProdTag) ProdTagContent = dbmix(NProdTagContent) def convert_decimal(x, default=None): return default if x is None else Decimal(x) price_override_name = (('prod_id', 'codigo'), ('cant_mayorista', 'threshold')) class PriceList(dbmix(NPriceList, price_override_name)): @classmethod def deserialize(cls, dict_input): prod = super(cls, PriceList).deserialize(dict_input)