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 _create_receiving_invoice(self): # We only let the user get this far if the receivings selected are for the # same branch and supplier supplier = self.receivings[0].purchase.supplier branch = self.receivings[0].branch # If the receiving is for another branch, we need a temporary identifier temporary_identifier = None if (api.sysparam.get_bool('SYNCHRONIZED_MODE') and api.get_current_branch(self.store) != branch): temporary_identifier = ReceivingInvoice.get_temporary_identifier( self.store) group = PaymentGroup(store=self.store, recipient=supplier.person) self.wizard.model = self.model = ReceivingInvoice( identifier=temporary_identifier, supplier=supplier, group=group, branch=branch, store=self.store, station=api.get_current_station(self.store), responsible=api.get_current_user(self.store)) for row in self.receivings: self.model.add_receiving(row.order)
def _create_receiving_order(self): supplier_id = self.purchases[0].supplier_id branch_id = self.purchases[0].branch_id # If the receiving is for another branch, we need a temporary identifier temporary_identifier = None if (api.sysparam.get_bool('SYNCHRONIZED_MODE') and api.get_current_branch(self.store).id != branch_id): temporary_identifier = ReceivingOrder.get_temporary_identifier( self.store) # We cannot create the model in the wizard since we haven't # selected a PurchaseOrder yet which ReceivingOrder depends on # Create the order here since this is the first place where we # actually have a purchase selected receiving_invoice = ReceivingInvoice(supplier=supplier_id, store=self.store, branch=branch_id, responsible=api.get_current_user( self.store)) self.wizard.model = self.model = ReceivingOrder( identifier=temporary_identifier, receiving_invoice=receiving_invoice, responsible=receiving_invoice.responsible, invoice_number=None, branch=branch_id, store=self.store) for row in self.purchases: self.model.add_purchase(row.purchase)
def _create_receiving_order(self): # since we will create a new receiving order, we should confirm the # purchase first. Note that the purchase may already be confirmed if self.model.status in [ PurchaseOrder.ORDER_PENDING, PurchaseOrder.ORDER_CONSIGNED ]: self.model.confirm(api.get_current_user(self.store)) temporary_identifier = None if self.wizard.is_for_another_branch(): temporary_identifier = ReceivingOrder.get_temporary_identifier( self.store) receiving_invoice = ReceivingInvoice( store=self.store, supplier=self.model.supplier, branch=self.model.branch, station=api.get_current_station(self.store), responsible=api.get_current_user(self.store)) receiving_model = ReceivingOrder( identifier=temporary_identifier, receiving_invoice=receiving_invoice, responsible=receiving_invoice.responsible, branch=self.model.branch, station=api.get_current_station(self.store), invoice_number=None, store=self.store) receiving_model.add_purchase(self.model) # Creates ReceivingOrderItem's for item in self.model.get_pending_items(): receiving_model.add_purchase_item(item) self.wizard.receiving_model = receiving_model
def on_invoice_number__validate(self, widget, value): if self.visual_mode: return if not 0 < value <= 999999999: return ValidationError( _("Invoice number must be between 1 and 999999999")) with api.new_store() as store: # Using a transaction to do the verification bellow because, # if we use self.store the changes on the invoice will be # saved at the same time in the database and it'll think # some valid invoices are invalid. is_valid = ReceivingInvoice.check_unique_invoice_number( store, value, self.model.supplier) if not is_valid: supplier_name = self.model.supplier.person.name return ValidationError(_(u'Invoice %d already exists for ' 'supplier %s.') % (value, supplier_name, ))
def _create_receiving_invoice(self): # We only let the user get this far if the receivings selected are for the # same branch and supplier supplier = self.receivings[0].purchase.supplier branch_id = self.receivings[0].branch_id # If the receiving is for another branch, we need a temporary identifier temporary_identifier = None if (api.sysparam.get_bool('SYNCHRONIZED_MODE') and api.get_current_branch(self.store).id != branch_id): temporary_identifier = ReceivingInvoice.get_temporary_identifier(self.store) group = PaymentGroup(store=self.store, recipient=supplier.person) self.wizard.model = self.model = ReceivingInvoice( identifier=temporary_identifier, supplier=supplier, group=group, branch_id=branch_id, store=self.store, responsible=api.get_current_user(self.store)) for row in self.receivings: self.model.add_receiving(row.order)
def _create_receiving_order(self): self.model.set_consigned() receiving_invoice = ReceivingInvoice(supplier=self.model.supplier, store=self.store, branch=self.model.branch, responsible=api.get_current_user( self.store)) receiving_model = ReceivingOrder( responsible=receiving_invoice.responsible, branch=self.model.branch, invoice_number=None, receiving_invoice=receiving_invoice, store=self.store) receiving_model.add_purchase(self.model) # Creates ReceivingOrderItem's for item in self.model.get_pending_items(): receiving_model.add_purchase_item(item) self.wizard.receiving_model = receiving_model
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_invoice = ReceivingInvoice(store=store, supplier=supplier, invoice_number=int(data.invoice), transporter=transporter) receiving_order = ReceivingOrder(responsible=login_user, receival_date=self.parse_date( data.due_date), invoice_number=int(data.invoice), branch=branch, receiving_invoice=receiving_invoice, 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()