'Set retail related fields from POS Profiles'

def set_pos_fields(self, for_validate=False):

    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(u'payments')) and (not for_validate)):
        pos_profile = (frappe.get_doc(u'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(u'Company', self.company, u'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
        if pos.get(u'account_for_change_amount'):
            self.account_for_change_amount = pos.get(u'account_for_change_amount')
        for fieldname in (u'territory', u'naming_series', u'currency', u'taxes_and_charges', u'letter_head', u'tc_name', u'selling_price_list', u'company', u'select_print_heading', u'cash_bank_account', u'write_off_account', u'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(u'update_stock'))
        for item in self.get(u'items'):
            if item.get(u'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)
        if (self.tc_name and (not self.terms)):
            self.terms = frappe.db.get_value(u'Terms    and    Conditions', self.tc_name, u'terms')
        if (self.taxes_and_charges and (not len(self.get(u'taxes')))):
            self.set_taxes()
    return pos
