Пример #1
0
    def set_pos_fields(self, for_validate=False):
        """Set retail related fields from POS Profiles"""
        if cint(self.is_pos) != 1:
            return

        from erpnext.stock.get_item_details import get_pos_profile_item_details, get_pos_profile
        pos = get_pos_profile(self.company)

        if not self.get('payments') and not for_validate:
            pos_profile = frappe.get_doc('POS Profile',
                                         pos.name) if pos else None
            update_multi_mode_option(self, pos_profile)

        if not self.account_for_change_amount:
            self.account_for_change_amount = frappe.db.get_value(
                'Company', self.company, 'default_cash_account')

        if pos:
            if not for_validate and not self.customer:
                self.customer = pos.customer
                self.mode_of_payment = pos.mode_of_payment
                # self.set_customer_defaults()

            if pos.get('account_for_change_amount'):
                self.account_for_change_amount = pos.get(
                    'account_for_change_amount')

            for fieldname in ('territory', 'naming_series', 'currency',
                              'taxes_and_charges', 'letter_head', 'tc_name',
                              'selling_price_list', 'company',
                              'select_print_heading', 'cash_bank_account',
                              'write_off_account', 'write_off_cost_center',
                              'apply_discount_on'):
                if (not for_validate) or (for_validate
                                          and not self.get(fieldname)):
                    self.set(fieldname, pos.get(fieldname))

            if not for_validate:
                self.update_stock = cint(pos.get("update_stock"))

            # set pos values in items
            for item in self.get("items"):
                if item.get('item_code'):
                    for fname, val in get_pos_profile_item_details(
                            pos, frappe._dict(item.as_dict()), pos).items():

                        if (not for_validate) or (for_validate
                                                  and not item.get(fname)):
                            item.set(fname, val)

            # fetch terms
            if self.tc_name and not self.terms:
                self.terms = frappe.db.get_value("Terms and Conditions",
                                                 self.tc_name, "terms")

            # fetch charges
            if self.taxes_and_charges and not len(self.get("taxes")):
                self.set_taxes()

        return pos
Пример #2
0
	def set_pos_fields(self, for_validate=False):
		"""Set retail related fields from POS Profiles"""
		if cint(self.is_pos) != 1:
			return

		from erpnext.stock.get_item_details import get_pos_profile_item_details, get_pos_profile
		if not self.pos_profile:
			pos_profile = get_pos_profile(self.company) or {}
			self.pos_profile = pos_profile.get('name')

		pos = {}
		if self.pos_profile:
			pos = frappe.get_doc('POS Profile', self.pos_profile)

		if not self.get('payments') and not for_validate:
			update_multi_mode_option(self, pos)

		if not self.account_for_change_amount:
			self.account_for_change_amount = frappe.db.get_value('Company', self.company, 'default_cash_account')

		if pos:
			self.allow_print_before_pay = pos.allow_print_before_pay

			if not for_validate and not self.customer:
				self.customer = pos.customer

			if pos.get('account_for_change_amount'):
				self.account_for_change_amount = pos.get('account_for_change_amount')

			for fieldname in ('territory', 'naming_series', 'currency', 'taxes_and_charges', 'letter_head', 'tc_name',
				'selling_price_list', 'company', 'select_print_heading', 'cash_bank_account',
				'write_off_account', 'write_off_cost_center', 'apply_discount_on'):
					if (not for_validate) or (for_validate and not self.get(fieldname)):
						self.set(fieldname, pos.get(fieldname))

			if not for_validate:
				self.update_stock = cint(pos.get("update_stock"))

			# set pos values in items
			for item in self.get("items"):
				if item.get('item_code'):
					for fname, val in get_pos_profile_item_details(pos,
						frappe._dict(item.as_dict()), pos).items():

						if (not for_validate) or (for_validate and not item.get(fname)):
							item.set(fname, val)

			# fetch terms
			if self.tc_name and not self.terms:
				self.terms = frappe.db.get_value("Terms and Conditions", self.tc_name, "terms")

			# fetch charges
			if self.taxes_and_charges and not len(self.get("taxes")):
				self.set_taxes()

		return pos
Пример #3
0
    def set_pos_fields(self, for_validate=False):
        """Set retail related fields from POS Profiles"""
        if cint(self.is_pos) != 1:
            return

        from erpnext.stock.get_item_details import get_pos_profile_item_details, get_pos_profile

        pos = get_pos_profile(self.company)

        if pos:
            if not for_validate and not self.customer:
                self.customer = pos.customer
                self.mode_of_payment = pos.mode_of_payment
                # self.set_customer_defaults()

            for fieldname in (
                "territory",
                "naming_series",
                "currency",
                "taxes_and_charges",
                "letter_head",
                "tc_name",
                "selling_price_list",
                "company",
                "select_print_heading",
                "cash_bank_account",
                "write_off_account",
                "write_off_cost_center",
            ):
                if (not for_validate) or (for_validate and not self.get(fieldname)):
                    self.set(fieldname, pos.get(fieldname))

            if not for_validate:
                self.update_stock = cint(pos.get("update_stock"))

                # set pos values in items
            for item in self.get("items"):
                if item.get("item_code"):
                    for fname, val in get_pos_profile_item_details(pos, frappe._dict(item.as_dict()), pos).items():

                        if (not for_validate) or (for_validate and not item.get(fname)):
                            item.set(fname, val)

                            # fetch terms
            if self.tc_name and not self.terms:
                self.terms = frappe.db.get_value("Terms and Conditions", self.tc_name, "terms")

                # fetch charges
            if self.taxes_and_charges and not len(self.get("taxes")):
                self.set_taxes()

        return pos
Пример #4
0
    def set_pos_fields(self, for_validate=False):
        """Set retail related fields from POS Profiles"""
        from erpnext.stock.get_item_details import get_pos_profile_item_details, get_pos_profile
        if not self.pos_profile:
            pos_profile = get_pos_profile(self.company) or {}
            if not pos_profile:
                frappe.throw(
                    _("No POS Profile found. Please create a New POS Profile first"
                      ))
            self.pos_profile = pos_profile.get('name')

        profile = {}
        if self.pos_profile:
            profile = frappe.get_doc('POS Profile', self.pos_profile)

        if not self.get('payments') and not for_validate:
            update_multi_mode_option(self, profile)

        if self.is_return and not for_validate:
            add_return_modes(self, profile)

        if profile:
            if not for_validate and not self.customer:
                self.customer = profile.customer

            self.ignore_pricing_rule = profile.ignore_pricing_rule
            self.account_for_change_amount = profile.get(
                'account_for_change_amount') or self.account_for_change_amount
            self.set_warehouse = profile.get('warehouse') or self.set_warehouse

            for fieldname in ('currency', 'letter_head', 'tc_name', 'company',
                              'select_print_heading', 'write_off_account',
                              'taxes_and_charges', 'write_off_cost_center',
                              'apply_discount_on', 'cost_center',
                              'tax_category', 'ignore_pricing_rule',
                              'company_address', 'update_stock'):
                if not for_validate:
                    self.set(fieldname, profile.get(fieldname))

            if self.customer:
                customer_price_list, customer_group, customer_currency = frappe.db.get_value(
                    "Customer", self.customer, [
                        'default_price_list', 'customer_group',
                        'default_currency'
                    ])
                customer_group_price_list = frappe.db.get_value(
                    "Customer Group", customer_group, 'default_price_list')
                selling_price_list = customer_price_list or customer_group_price_list or profile.get(
                    'selling_price_list')
                if customer_currency != profile.get('currency'):
                    self.set('currency', customer_currency)

            else:
                selling_price_list = profile.get('selling_price_list')

            if selling_price_list:
                self.set('selling_price_list', selling_price_list)

            # set pos values in items
            for item in self.get("items"):
                if item.get('item_code'):
                    profile_details = get_pos_profile_item_details(
                        profile.get("company"), frappe._dict(item.as_dict()),
                        profile)
                    for fname, val in iteritems(profile_details):
                        if (not for_validate) or (for_validate
                                                  and not item.get(fname)):
                            item.set(fname, val)

            # fetch terms
            if self.tc_name and not self.terms:
                self.terms = frappe.db.get_value("Terms and Conditions",
                                                 self.tc_name, "terms")

            # fetch charges
            if self.taxes_and_charges and not len(self.get("taxes")):
                self.set_taxes()

        if not self.account_for_change_amount:
            self.account_for_change_amount = frappe.get_cached_value(
                'Company', self.company, 'default_cash_account')

        return profile
Пример #5
0
	def set_pos_fields(self, for_validate=False):
		"""Set retail related fields from POS Profiles"""
		from erpnext.stock.get_item_details import get_pos_profile, get_pos_profile_item_details

		if not self.pos_profile:
			pos_profile = get_pos_profile(self.company) or {}
			if not pos_profile:
				frappe.throw(_("No POS Profile found. Please create a New POS Profile first"))
			self.pos_profile = pos_profile.get("name")

		profile = {}
		if self.pos_profile:
			profile = frappe.get_doc("POS Profile", self.pos_profile)

		if not self.get("payments") and not for_validate:
			update_multi_mode_option(self, profile)

		if self.is_return and not for_validate:
			add_return_modes(self, profile)

		if profile:
			if not for_validate and not self.customer:
				self.customer = profile.customer

			self.account_for_change_amount = (
				profile.get("account_for_change_amount") or self.account_for_change_amount
			)
			self.set_warehouse = profile.get("warehouse") or self.set_warehouse

			for fieldname in (
				"currency",
				"letter_head",
				"tc_name",
				"company",
				"select_print_heading",
				"write_off_account",
				"taxes_and_charges",
				"write_off_cost_center",
				"apply_discount_on",
				"cost_center",
				"tax_category",
				"ignore_pricing_rule",
				"company_address",
				"update_stock",
			):
				if not for_validate:
					self.set(fieldname, profile.get(fieldname))

			if self.customer:
				customer_price_list, customer_group, customer_currency = frappe.db.get_value(
					"Customer", self.customer, ["default_price_list", "customer_group", "default_currency"]
				)
				customer_group_price_list = frappe.db.get_value(
					"Customer Group", customer_group, "default_price_list"
				)
				selling_price_list = (
					customer_price_list or customer_group_price_list or profile.get("selling_price_list")
				)
				if customer_currency != profile.get("currency"):
					self.set("currency", customer_currency)

			else:
				selling_price_list = profile.get("selling_price_list")

			if selling_price_list:
				self.set("selling_price_list", selling_price_list)

			# set pos values in items
			for item in self.get("items"):
				if item.get("item_code"):
					profile_details = get_pos_profile_item_details(
						profile.get("company"), frappe._dict(item.as_dict()), profile
					)
					for fname, val in profile_details.items():
						if (not for_validate) or (for_validate and not item.get(fname)):
							item.set(fname, val)

			# fetch terms
			if self.tc_name and not self.terms:
				self.terms = frappe.db.get_value("Terms and Conditions", self.tc_name, "terms")

			# fetch charges
			if self.taxes_and_charges and not len(self.get("taxes")):
				self.set_taxes()

		if not self.account_for_change_amount:
			self.account_for_change_amount = frappe.get_cached_value(
				"Company", self.company, "default_cash_account"
			)

		return profile