def set_pos_fields(self, for_validate=False):
        """Set retail related fields from pos settings"""
        if cint(self.is_pos) != 1:
            return

        from erpnext.stock.get_item_details import get_pos_settings_item_details, get_pos_settings

        pos = get_pos_settings(self.company)

        if pos:
            if not for_validate and not self.customer:
                self.customer = pos.customer
                # 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",
            ):
                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("entries"):
                if item.get("item_code"):
                    for fname, val in get_pos_settings_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("other_charges")):
                self.set_taxes("other_charges", "taxes_and_charges")
Beispiel #2
0
    def set_pos_fields(self, for_validate=False):
        """Set retail related fields from pos settings"""
        if cint(self.is_pos) != 1:
            return

        from erpnext.stock.get_item_details import get_pos_settings_item_details, get_pos_settings
        pos = get_pos_settings(self.company)

        if pos:
            if not for_validate and not self.customer:
                self.customer = pos.customer
                # 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_settings_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("taxes", "taxes_and_charges")