def create_receiving_order(self, station): notes = u"Created automatically with Stoq-Link" # TODO Eventually get this from the invoice data. cfop = sysparam.get_object(self.store, 'DEFAULT_RECEIVING_CFOP') receiving_invoice = ReceivingInvoice( store=self.store, freight_total=self.freight_cost, invoice_number=self.invoice_number, invoice_total=self.total_cost, supplier=self.purchase_order.supplier, branch=self.branch, responsible=self.user, station=station) receiving_order = ReceivingOrder(store=self.store, branch=self.branch, station=station, notes=notes, cfop=cfop, confirm_date=datetime.datetime.now(), status=u'closed', receiving_invoice=receiving_invoice) receiving_order.add_purchase(self.purchase_order) for item in self.purchase_order.get_items(): receiving_order.add_purchase_item(item=item) if self.freight_type == PurchaseOrder.FREIGHT_CIF: receiving_order.update_payments(create_freight_payment=True) receiving_invoice.freight_type = receiving_invoice.guess_freight_type() receiving_order.confirm(self.user) return receiving_order
def process_one(self, data, fields, store): person = store.find(Person, name=data.supplier_name).one() if person is None or person.supplier is None: raise ValueError(u"%s is not a valid supplier" % (data.supplier_name, )) supplier = person.supplier person = store.find(Person, name=data.transporter_name).one() if person is None or person.transporter is None: raise ValueError(u"%s is not a valid transporter" % (data.transporter_name, )) transporter = person.transporter person = store.find(Person, name=data.branch_name).one() if person is None or person.branch is None: raise ValueError(u"%s is not a valid branch" % (data.branch_name, )) branch = person.branch login_user = store.find(LoginUser, username=u'admin').one() group = PaymentGroup(store=store) purchase = PurchaseOrder(store=store, status=PurchaseOrder.ORDER_PENDING, open_date=self.parse_date(data.due_date), supplier=supplier, transporter=transporter, group=group, responsible=get_current_user(store), branch=branch) for sellable in self.parse_multi(Sellable, data.sellable_list, store): if not sellable.product: continue PurchaseItem(store=store, quantity=int(data.quantity), base_cost=sellable.cost, sellable=sellable, order=purchase) method = PaymentMethod.get_by_name(store, data.payment_method) method.create_payment(Payment.TYPE_OUT, purchase.group, branch, purchase.purchase_total, self.parse_date(data.due_date)) purchase.confirm() for payment in purchase.payments: payment.open_date = purchase.open_date receiving_order = ReceivingOrder(responsible=login_user, supplier=supplier, invoice_number=int(data.invoice), transporter=transporter, branch=branch, store=store) receiving_order.add_purchase(purchase) for purchase_item in purchase.get_items(): ReceivingOrderItem(store=store, cost=purchase_item.sellable.cost, sellable=purchase_item.sellable, quantity=int(data.quantity), purchase_item=purchase_item, receiving_order=receiving_order) receiving_order.confirm()
def process_one(self, data, fields, store): person = store.find(Person, name=data.supplier_name).one() if person is None or person.supplier is None: raise ValueError(u"%s is not a valid supplier" % ( data.supplier_name, )) supplier = person.supplier person = store.find(Person, name=data.transporter_name).one() if person is None or person.transporter is None: raise ValueError(u"%s is not a valid transporter" % ( data.transporter_name, )) transporter = person.transporter person = store.find(Person, name=data.branch_name).one() if person is None or person.branch is None: raise ValueError(u"%s is not a valid branch" % ( data.branch_name, )) branch = person.branch person = store.find(Person, name=data.user_name).one() if person is None or person.login_user is None: raise ValueError(u"%s is not a valid user" % ( data.user_name, )) login_user = person.login_user group = PaymentGroup(store=store) purchase = PurchaseOrder(store=store, status=PurchaseOrder.ORDER_PENDING, supplier=supplier, transporter=transporter, group=group, responsible=get_current_user(store), branch=branch) for sellable in self.parse_multi(Sellable, data.sellable_list, store): if not sellable.product: continue PurchaseItem(store=store, quantity=int(data.quantity), base_cost=sellable.cost, sellable=sellable, order=purchase) method = PaymentMethod.get_by_name(store, data.payment_method) method.create_payment(Payment.TYPE_OUT, purchase.group, branch, purchase.purchase_total, self.parse_date(data.due_date)) purchase.confirm() receiving_order = ReceivingOrder(responsible=login_user, supplier=supplier, invoice_number=int(data.invoice), transporter=transporter, branch=branch, store=store) receiving_order.add_purchase(purchase) for purchase_item in purchase.get_items(): ReceivingOrderItem( store=store, cost=purchase_item.sellable.cost, sellable=purchase_item.sellable, quantity=int(data.quantity), purchase_item=purchase_item, receiving_order=receiving_order ) receiving_order.confirm()