blob: 2b6e3af52ab5cd13f8987e8a733c978970df6c41 [file] [log] [blame]
Gaurava4aa80f2019-01-06 12:40:28 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3# coding=utf-8
4
5from __future__ import unicode_literals
6
7import frappe
Gauravf1e28e02019-02-13 16:46:24 +05308from frappe import _
Gaurava4aa80f2019-01-06 12:40:28 +05309from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
Gauravf1e28e02019-02-13 16:46:24 +053010from erpnext.regional.italy import fiscal_regimes, tax_exemption_reasons, mode_of_payment_codes, vat_collectability_options
Gaurava4aa80f2019-01-06 12:40:28 +053011
12def setup(company=None, patch=True):
Saurabh9fcfc632019-02-20 13:03:50 +053013 make_custom_fields()
14 setup_report()
Gaurava4aa80f2019-01-06 12:40:28 +053015
16def make_custom_fields(update=True):
Saurabh9fcfc632019-02-20 13:03:50 +053017 invoice_item_fields = [
18 dict(fieldname='tax_rate', label='Tax Rate',
Gauravf1e28e02019-02-13 16:46:24 +053019 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")
Saurabh9fcfc632019-02-20 13:03:50 +053027 ]
Gauravf1e28e02019-02-13 16:46:24 +053028
Saurabh9fcfc632019-02-20 13:03:50 +053029 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,
Gauravb30a9b12019-03-01 12:33:19 +053035 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), fiscal_regimes))),
Saurabh9fcfc632019-02-20 13:03:50 +053036 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,
Gauravb30a9b12019-03-01 12:33:19 +053040 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), vat_collectability_options))),
Saurabh9fcfc632019-02-20 13:03:50 +053041 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',
Gauravb30a9b12019-03-01 12:33:19 +053060 options="\n" + "\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), tax_exemption_reasons))),
Saurabh9fcfc632019-02-20 13:03:50 +053061 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,
Gauravb30a9b12019-03-01 12:33:19 +053083 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), mode_of_payment_codes)))
Saurabh9fcfc632019-02-20 13:03:50 +053084 ],
85 'Payment Schedule': [
86 dict(fieldname='mode_of_payment_code', label='Code',
87 fieldtype='Select', insert_after='mode_of_payment', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +053088 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), mode_of_payment_codes)),
Saurabh9fcfc632019-02-20 13:03:50 +053089 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"),
Gauravb30a9b12019-03-01 12:33:19 +053093 dict(fieldname='bank_account_name', label='Bank Name',
Saurabh9fcfc632019-02-20 13:03:50 +053094 fieldtype='Data', insert_after='bank_account', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +053095 fetch_from="bank_account.bank", read_only=1),
Saurabh9fcfc632019-02-20 13:03:50 +053096 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),
Gauravb30a9b12019-03-01 12:33:19 +0530102 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),
Saurabh9fcfc632019-02-20 13:03:50 +0530105 ],
106 "Sales Invoice": [
107 dict(fieldname='vat_collectability', label='VAT Collectability',
108 fieldtype='Select', insert_after='taxes_and_charges', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +0530109 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), vat_collectability_options)),
Saurabh9fcfc632019-02-20 13:03:50 +0530110 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,
Gauravf1e28e02019-02-13 16:46:24 +0530129 'Sales Order Item': invoice_item_fields,
130 'Delivery Note Item': invoice_item_fields,
Saurabh9fcfc632019-02-20 13:03:50 +0530131 'Sales Invoice Item': invoice_item_fields,
Gauravf1e28e02019-02-13 16:46:24 +0530132 '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,
Saurabh9fcfc632019-02-20 13:03:50 +0530136 'Address': [
137 dict(fieldname='country_code', label='Country Code',
Rohit Waghchaure74cfe572019-02-26 20:08:26 +0530138 fieldtype='Data', insert_after='country', print_hide=1, read_only=0,
Saurabh9fcfc632019-02-20 13:03:50 +0530139 fetch_from="country.code"),
140 dict(fieldname='state_code', label='State Code',
141 fieldtype='Data', insert_after='state', print_hide=1)
142 ]
143 }
Gaurava4aa80f2019-01-06 12:40:28 +0530144
Saurabh9fcfc632019-02-20 13:03:50 +0530145 create_custom_fields(custom_fields, ignore_validate = frappe.flags.in_patch, update=update)
Gauravf1e28e02019-02-13 16:46:24 +0530146
147def setup_report():
Saurabh9fcfc632019-02-20 13:03:50 +0530148 report_name = 'Electronic Invoice Register'
Gauravf1e28e02019-02-13 16:46:24 +0530149
Saurabh9fcfc632019-02-20 13:03:50 +0530150 frappe.db.sql(""" update `tabReport` set disabled = 0 where
151 name = %s """, report_name)
Gauravf1e28e02019-02-13 16:46:24 +0530152
Saurabh9fcfc632019-02-20 13:03:50 +0530153 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()