Gaurav | a4aa80f | 2019-01-06 12:40:28 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | # coding=utf-8 |
| 4 | |
| 5 | from __future__ import unicode_literals |
| 6 | |
| 7 | import frappe |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 8 | from frappe import _ |
Gaurav | a4aa80f | 2019-01-06 12:40:28 +0530 | [diff] [blame] | 9 | from frappe.custom.doctype.custom_field.custom_field import create_custom_fields |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 10 | from erpnext.regional.italy import fiscal_regimes, tax_exemption_reasons, mode_of_payment_codes, vat_collectability_options |
Gaurav | a4aa80f | 2019-01-06 12:40:28 +0530 | [diff] [blame] | 11 | |
| 12 | def setup(company=None, patch=True): |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 13 | make_custom_fields() |
| 14 | setup_report() |
Gaurav | a4aa80f | 2019-01-06 12:40:28 +0530 | [diff] [blame] | 15 | |
| 16 | def make_custom_fields(update=True): |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 17 | invoice_item_fields = [ |
| 18 | dict(fieldname='tax_rate', label='Tax Rate', |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 19 | fieldtype='Float', insert_after='description', |
| 20 | print_hide=1, hidden=1, read_only=1), |
| 21 | dict(fieldname='tax_amount', label='Tax Amount', |
| 22 | fieldtype='Currency', insert_after='tax_rate', |
| 23 | print_hide=1, hidden=1, read_only=1, options="currency"), |
| 24 | dict(fieldname='total_amount', label='Total Amount', |
| 25 | fieldtype='Currency', insert_after='tax_amount', |
| 26 | print_hide=1, hidden=1, read_only=1, options="currency") |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 27 | ] |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 28 | |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 29 | custom_fields = { |
| 30 | 'Company': [ |
| 31 | dict(fieldname='sb_e_invoicing', label='E-Invoicing', |
| 32 | fieldtype='Section Break', insert_after='date_of_establishment', print_hide=1), |
| 33 | dict(fieldname='fiscal_regime', label='Fiscal Regime', |
| 34 | fieldtype='Select', insert_after='sb_e_invoicing', print_hide=1, |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 35 | options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), fiscal_regimes))), |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 36 | dict(fieldname='fiscal_code', label='Fiscal Code', fieldtype='Data', insert_after='fiscal_regime', print_hide=1, |
| 37 | description=_("Applicable if the company is an Individual or a Proprietorship")), |
| 38 | dict(fieldname='vat_collectability', label='VAT Collectability', |
| 39 | fieldtype='Select', insert_after='fiscal_code', print_hide=1, |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 40 | options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), vat_collectability_options))), |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 41 | dict(fieldname='cb_e_invoicing1', fieldtype='Column Break', insert_after='vat_collectability', print_hide=1), |
| 42 | dict(fieldname='registrar_office_province', label='Province of the Registrar Office', |
| 43 | fieldtype='Data', insert_after='cb_e_invoicing1', print_hide=1, length=2), |
| 44 | dict(fieldname='registration_number', label='Registration Number', |
| 45 | fieldtype='Data', insert_after='registrar_office_province', print_hide=1, length=20), |
| 46 | dict(fieldname='share_capital_amount', label='Share Capital', |
| 47 | fieldtype='Currency', insert_after='registration_number', print_hide=1, |
| 48 | description=_('Applicable if the company is SpA, SApA or SRL')), |
| 49 | dict(fieldname='no_of_members', label='No of Members', |
| 50 | fieldtype='Select', insert_after='share_capital_amount', print_hide=1, |
| 51 | options="\nSU-Socio Unico\nSM-Piu Soci", description=_("Applicable if the company is a limited liability company")), |
| 52 | dict(fieldname='liquidation_state', label='Liquidation State', |
| 53 | fieldtype='Select', insert_after='no_of_members', print_hide=1, |
| 54 | options="\nLS-In Liquidazione\nLN-Non in Liquidazione") |
| 55 | ], |
| 56 | 'Sales Taxes and Charges': [ |
| 57 | dict(fieldname='tax_exemption_reason', label='Tax Exemption Reason', |
| 58 | fieldtype='Select', insert_after='included_in_print_rate', print_hide=1, |
| 59 | depends_on='eval:doc.charge_type!="Actual" && doc.rate==0.0', |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 60 | options="\n" + "\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), tax_exemption_reasons))), |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 61 | dict(fieldname='tax_exemption_law', label='Tax Exempt Under', |
| 62 | fieldtype='Text', insert_after='tax_exemption_reason', print_hide=1, |
| 63 | depends_on='eval:doc.charge_type!="Actual" && doc.rate==0.0') |
| 64 | ], |
| 65 | 'Customer': [ |
| 66 | dict(fieldname='fiscal_code', label='Fiscal Code', fieldtype='Data', insert_after='tax_id', print_hide=1), |
| 67 | dict(fieldname='recipient_code', label='Recipient Code', |
| 68 | fieldtype='Data', insert_after='fiscal_code', print_hide=1, default="0000000"), |
| 69 | dict(fieldname='pec', label='Recipient PEC', |
| 70 | fieldtype='Data', insert_after='fiscal_code', print_hide=1), |
| 71 | dict(fieldname='is_public_administration', label='Is Public Administration', |
| 72 | fieldtype='Check', insert_after='is_internal_customer', print_hide=1, |
| 73 | description=_("Set this if the customer is a Public Administration company."), |
| 74 | depends_on='eval:doc.customer_type=="Company"'), |
| 75 | dict(fieldname='first_name', label='First Name', fieldtype='Data', |
| 76 | insert_after='salutation', print_hide=1, depends_on='eval:doc.customer_type!="Company"'), |
| 77 | dict(fieldname='last_name', label='Last Name', fieldtype='Data', |
| 78 | insert_after='first_name', print_hide=1, depends_on='eval:doc.customer_type!="Company"') |
| 79 | ], |
| 80 | 'Mode of Payment': [ |
| 81 | dict(fieldname='mode_of_payment_code', label='Code', |
| 82 | fieldtype='Select', insert_after='included_in_print_rate', print_hide=1, |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 83 | options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), mode_of_payment_codes))) |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 84 | ], |
| 85 | 'Payment Schedule': [ |
| 86 | dict(fieldname='mode_of_payment_code', label='Code', |
| 87 | fieldtype='Select', insert_after='mode_of_payment', print_hide=1, |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 88 | options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), mode_of_payment_codes)), |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 89 | fetch_from="mode_of_payment.mode_of_payment_code", read_only=1), |
| 90 | dict(fieldname='bank_account', label='Bank Account', |
| 91 | fieldtype='Link', insert_after='mode_of_payment_code', print_hide=1, |
| 92 | options="Bank Account"), |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 93 | dict(fieldname='bank_account_name', label='Bank Name', |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 94 | fieldtype='Data', insert_after='bank_account', print_hide=1, |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 95 | fetch_from="bank_account.bank", read_only=1), |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 96 | dict(fieldname='bank_account_no', label='Bank Account No', |
| 97 | fieldtype='Data', insert_after='bank_account_name', print_hide=1, |
| 98 | fetch_from="bank_account.bank_account_no", read_only=1), |
| 99 | dict(fieldname='bank_account_iban', label='IBAN', |
| 100 | fieldtype='Data', insert_after='bank_account_name', print_hide=1, |
| 101 | fetch_from="bank_account.iban", read_only=1), |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 102 | dict(fieldname='bank_account_swift_number', label='Swift Code (BIC)', |
| 103 | fieldtype='Data', insert_after='bank_account_iban', print_hide=1, |
| 104 | fetch_from="bank_account.swift_number", read_only=1), |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 105 | ], |
| 106 | "Sales Invoice": [ |
| 107 | dict(fieldname='vat_collectability', label='VAT Collectability', |
| 108 | fieldtype='Select', insert_after='taxes_and_charges', print_hide=1, |
Gaurav | b30a9b1 | 2019-03-01 12:33:19 +0530 | [diff] [blame] | 109 | options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), vat_collectability_options)), |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 110 | fetch_from="company.vat_collectability"), |
| 111 | dict(fieldname='sb_e_invoicing_reference', label='E-Invoicing', |
| 112 | fieldtype='Section Break', insert_after='pos_total_qty', print_hide=1), |
| 113 | dict(fieldname='company_tax_id', label='Company Tax ID', |
| 114 | fieldtype='Data', insert_after='sb_e_invoicing_reference', print_hide=1, read_only=1, |
| 115 | fetch_from="company.tax_id"), |
| 116 | dict(fieldname='company_fiscal_code', label='Company Fiscal Code', |
| 117 | fieldtype='Data', insert_after='company_tax_id', print_hide=1, read_only=1, |
| 118 | fetch_from="company.fiscal_code"), |
| 119 | dict(fieldname='company_fiscal_regime', label='Company Fiscal Regime', |
| 120 | fieldtype='Data', insert_after='company_fiscal_code', print_hide=1, read_only=1, |
| 121 | fetch_from="company.fiscal_regime"), |
| 122 | dict(fieldname='cb_e_invoicing_reference', fieldtype='Column Break', |
| 123 | insert_after='company_fiscal_regime', print_hide=1), |
| 124 | dict(fieldname='customer_fiscal_code', label='Customer Fiscal Code', |
| 125 | fieldtype='Data', insert_after='cb_e_invoicing_reference', read_only=1, |
| 126 | fetch_from="customer.fiscal_code"), |
| 127 | ], |
| 128 | 'Purchase Invoice Item': invoice_item_fields, |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 129 | 'Sales Order Item': invoice_item_fields, |
| 130 | 'Delivery Note Item': invoice_item_fields, |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 131 | 'Sales Invoice Item': invoice_item_fields, |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 132 | 'Quotation Item': invoice_item_fields, |
| 133 | 'Purchase Order Item': invoice_item_fields, |
| 134 | 'Purchase Receipt Item': invoice_item_fields, |
| 135 | 'Supplier Quotation Item': invoice_item_fields, |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 136 | 'Address': [ |
| 137 | dict(fieldname='country_code', label='Country Code', |
Rohit Waghchaure | 74cfe57 | 2019-02-26 20:08:26 +0530 | [diff] [blame] | 138 | fieldtype='Data', insert_after='country', print_hide=1, read_only=0, |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 139 | fetch_from="country.code"), |
| 140 | dict(fieldname='state_code', label='State Code', |
| 141 | fieldtype='Data', insert_after='state', print_hide=1) |
| 142 | ] |
| 143 | } |
Gaurav | a4aa80f | 2019-01-06 12:40:28 +0530 | [diff] [blame] | 144 | |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 145 | create_custom_fields(custom_fields, ignore_validate = frappe.flags.in_patch, update=update) |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 146 | |
| 147 | def setup_report(): |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 148 | report_name = 'Electronic Invoice Register' |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 149 | |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 150 | frappe.db.sql(""" update `tabReport` set disabled = 0 where |
| 151 | name = %s """, report_name) |
Gaurav | f1e28e0 | 2019-02-13 16:46:24 +0530 | [diff] [blame] | 152 | |
Saurabh | 9fcfc63 | 2019-02-20 13:03:50 +0530 | [diff] [blame] | 153 | if not frappe.db.get_value('Custom Role', dict(report=report_name)): |
| 154 | frappe.get_doc(dict( |
| 155 | doctype='Custom Role', |
| 156 | report=report_name, |
| 157 | roles= [ |
| 158 | dict(role='Accounts User'), |
| 159 | dict(role='Accounts Manager') |
| 160 | ] |
| 161 | )).insert() |