Beispiel #1
0
    def get_last_purchase_rate(self, obj):
        """get last purchase rates for all items"""
        doc_name = obj.doc.name
        conversion_rate = flt(obj.doc.fields.get('conversion_rate')) or 1.0

        for d in getlist(obj.doclist, obj.fname):
            if d.item_code:
                last_purchase_details = get_last_purchase_details(
                    d.item_code, doc_name)

                if last_purchase_details:
                    d.purchase_ref_rate = last_purchase_details[
                        'purchase_ref_rate'] * (flt(d.conversion_factor)
                                                or 1.0)
                    d.discount_rate = last_purchase_details['discount_rate']
                    d.purchase_rate = last_purchase_details[
                        'purchase_rate'] * (flt(d.conversion_factor) or 1.0)
                    d.import_ref_rate = d.purchase_ref_rate / conversion_rate
                    d.import_rate = d.purchase_rate / conversion_rate
                else:
                    # if no last purchase found, reset all values to 0
                    d.purchase_ref_rate = d.purchase_rate = d.import_ref_rate = d.import_rate = d.discount_rate = 0

                    item_last_purchase_rate = webnotes.conn.get_value(
                        "Item", d.item_code, "last_purchase_rate")
                    if item_last_purchase_rate:
                        d.purchase_ref_rate = d.purchase_rate = d.import_ref_rate \
                         = d.import_rate = item_last_purchase_rate
Beispiel #2
0
	def update_last_purchase_rate(self, obj, is_submit):
		"""updates last_purchase_rate in item table for each item"""
		
		import webnotes.utils
		this_purchase_date = webnotes.utils.getdate(obj.doc.fields.get('posting_date') or obj.doc.fields.get('transaction_date'))
		
		for d in getlist(obj.doclist,obj.fname):
			# get last purchase details
			last_purchase_details = get_last_purchase_details(d.item_code, obj.doc.name)

			# compare last purchase date and this transaction's date
			last_purchase_rate = None
			if last_purchase_details and \
					(last_purchase_details.purchase_date > this_purchase_date):
				last_purchase_rate = last_purchase_details['purchase_rate']
			elif is_submit == 1:
				# even if this transaction is the latest one, it should be submitted
				# for it to be considered for latest purchase rate
				if flt(d.conversion_factor):
					last_purchase_rate = flt(d.purchase_rate) / flt(d.conversion_factor)
				else:
					msgprint(_("Row ") + cstr(d.idx) + ": " + 
						_("UOM Conversion Factor is mandatory"), raise_exception=1)

			# update last purchsae rate
			if last_purchase_rate:
				webnotes.conn.sql("update `tabItem` set last_purchase_rate = %s where name = %s",
						(flt(last_purchase_rate),d.item_code))
Beispiel #3
0
    def update_last_purchase_rate(self, obj, is_submit):
        """updates last_purchase_rate in item table for each item"""

        import webnotes.utils
        this_purchase_date = webnotes.utils.getdate(
            obj.doc.fields.get('posting_date')
            or obj.doc.fields.get('transaction_date'))

        for d in getlist(obj.doclist, obj.fname):
            # get last purchase details
            last_purchase_details = get_last_purchase_details(
                d.item_code, obj.doc.name)

            # compare last purchase date and this transaction's date
            last_purchase_rate = None
            if last_purchase_details and \
              (last_purchase_details.purchase_date > this_purchase_date):
                last_purchase_rate = last_purchase_details['purchase_rate']
            elif is_submit == 1:
                # even if this transaction is the latest one, it should be submitted
                # for it to be considered for latest purchase rate
                if flt(d.conversion_factor):
                    last_purchase_rate = flt(d.purchase_rate) / flt(
                        d.conversion_factor)
                else:
                    msgprint(_("Row ") + cstr(d.idx) + ": " +
                             _("UOM Conversion Factor is mandatory"),
                             raise_exception=1)

            # update last purchsae rate
            if last_purchase_rate:
                webnotes.conn.sql(
                    "update `tabItem` set last_purchase_rate = %s where name = %s",
                    (flt(last_purchase_rate), d.item_code))
Beispiel #4
0
 def get_indent_details(self):
     if self.doc.indent_no:
         get_obj("DocType Mapper", "Material Request-Purchase Order").dt_map(
             "Material Request",
             "Purchase Order",
             self.doc.indent_no,
             self.doc,
             self.doclist,
             "[['Material Request','Purchase Order'],['Material Request Item', 'Purchase Order Item']]",
         )
         pcomm = get_obj("Purchase Common")
         for d in getlist(self.doclist, "po_details"):
             if d.item_code and not d.purchase_rate:
                 last_purchase_details = get_last_purchase_details(d.item_code, self.doc.name)
                 if last_purchase_details:
                     conversion_factor = d.conversion_factor or 1.0
                     conversion_rate = self.doc.fields.get("conversion_rate") or 1.0
                     d.purchase_ref_rate = last_purchase_details["purchase_ref_rate"] * conversion_factor
                     d.discount_rate = last_purchase_details["discount_rate"]
                     d.purchase_rate = last_purchase_details["purchase_rate"] * conversion_factor
                     d.import_ref_rate = d.purchase_ref_rate / conversion_rate
                     d.import_rate = d.purchase_rate / conversion_rate
                 else:
                     d.purchase_ref_rate = (
                         d.discount_rate
                     ) = d.purchase_rate = d.import_ref_rate = d.import_rate = 0.0
Beispiel #5
0
 def get_indent_details(self):
     if self.doc.indent_no:
         get_obj(
             'DocType Mapper', 'Purchase Request-Purchase Order'
         ).dt_map(
             'Purchase Request', 'Purchase Order', self.doc.indent_no,
             self.doc, self.doclist,
             "[['Purchase Request','Purchase Order'],['Purchase Request Item', 'Purchase Order Item']]"
         )
         pcomm = get_obj('Purchase Common')
         for d in getlist(self.doclist, 'po_details'):
             if d.item_code and not d.purchase_rate:
                 last_purchase_details = get_last_purchase_details(
                     d.item_code, self.doc.name)
                 if last_purchase_details:
                     conversion_factor = d.conversion_factor or 1.0
                     conversion_rate = self.doc.fields.get(
                         'conversion_rate') or 1.0
                     d.purchase_ref_rate = last_purchase_details[
                         'purchase_ref_rate'] * conversion_factor
                     d.discount_rate = last_purchase_details[
                         'discount_rate']
                     d.purchase_rate = last_purchase_details[
                         'purchase_rate'] * conversion_factor
                     d.import_ref_rate = d.purchase_ref_rate / conversion_rate
                     d.import_rate = d.purchase_rate / conversion_rate
                 else:
                     d.purchase_ref_rate = d.discount_rate = d.purchase_rate = d.import_ref_rate = d.import_rate = 0.0
    def update_last_purchase_rate(self, obj, is_submit):
        """updates last_purchase_rate in item table for each item"""

        import webnotes.utils

        this_purchase_date = webnotes.utils.getdate(
            obj.doc.fields.get("posting_date") or obj.doc.fields.get("transaction_date")
        )

        for d in getlist(obj.doclist, obj.fname):
            # get last purchase details
            last_purchase_details = get_last_purchase_details(d.item_code, obj.doc.name)

            # compare last purchase date and this transaction's date
            last_purchase_rate = None
            if last_purchase_details and (last_purchase_details.purchase_date > this_purchase_date):
                last_purchase_rate = last_purchase_details["purchase_rate"]
            elif is_submit == 1:
                # even if this transaction is the latest one, it should be submitted
                # for it to be considered for latest purchase rate
                last_purchase_rate = flt(d.purchase_rate) / flt(d.conversion_factor)

                # update last purchsae rate
            if last_purchase_rate:
                sql(
                    "update `tabItem` set last_purchase_rate = %s where name = %s",
                    (flt(last_purchase_rate), d.item_code),
                )
Beispiel #7
0
	def get_indent_details(self):
		if self.doc.indent_no:
			get_obj('DocType Mapper','Material Request-Purchase Order').dt_map('Material Request','Purchase Order',self.doc.indent_no, self.doc, self.doclist, "[['Material Request','Purchase Order'],['Material Request Item', 'Purchase Order Item']]")
			for d in getlist(self.doclist, 'po_details'):
				if d.item_code and not d.purchase_rate:
					last_purchase_details = get_last_purchase_details(d.item_code, self.doc.name)
					if last_purchase_details:
						conversion_factor = d.conversion_factor or 1.0
						conversion_rate = self.doc.fields.get('conversion_rate') or 1.0
						d.purchase_ref_rate = last_purchase_details['purchase_ref_rate'] * conversion_factor
						d.discount_rate = last_purchase_details['discount_rate']
						d.purchase_rate = last_purchase_details['purchase_rate'] * conversion_factor
						d.import_ref_rate = d.purchase_ref_rate / conversion_rate
						d.import_rate = d.purchase_rate / conversion_rate						
					else:
						d.purchase_ref_rate = d.discount_rate = d.purchase_rate = d.import_ref_rate = d.import_rate = 0.0
Beispiel #8
0
	def get_last_purchase_rate(self, obj):
		"""get last purchase rates for all items"""
		doc_name = obj.doc.name
		conversion_rate = flt(obj.doc.fields.get('conversion_rate')) or 1.0
		
		for d in getlist(obj.doclist, obj.fname):
			if d.item_code:
				last_purchase_details = get_last_purchase_details(d.item_code, doc_name)

				if last_purchase_details:
					d.purchase_ref_rate = last_purchase_details['purchase_ref_rate'] * (flt(d.conversion_factor) or 1.0)
					d.discount_rate = last_purchase_details['discount_rate']
					d.purchase_rate = last_purchase_details['purchase_rate'] * (flt(d.conversion_factor) or 1.0)
					d.import_ref_rate = d.purchase_ref_rate / conversion_rate
					d.import_rate = d.purchase_rate / conversion_rate
				else:
					# if no last purchase found, reset all values to 0
					d.purchase_ref_rate = d.purchase_rate = d.import_ref_rate = d.import_rate = d.discount_rate = 0
					
					item_last_purchase_rate = webnotes.conn.get_value("Item",
						d.item_code, "last_purchase_rate")
					if item_last_purchase_rate:
						d.purchase_ref_rate = d.purchase_rate = d.import_ref_rate \
							= d.import_rate = item_last_purchase_rate
Beispiel #9
0
	def set_last_purchase_rate(self, newdn):
		from buying.utils import get_last_purchase_details
		last_purchase_rate = get_last_purchase_details(newdn).get("purchase_rate", 0)
		webnotes.conn.set_value("Item", newdn, "last_purchase_rate", last_purchase_rate)
Beispiel #10
0
 def set_last_purchase_rate(self, newdn):
     from buying.utils import get_last_purchase_details
     last_purchase_rate = get_last_purchase_details(newdn).get(
         "purchase_rate", 0)
     webnotes.conn.set_value("Item", newdn, "last_purchase_rate",
                             last_purchase_rate)