blob: a9de2d1f18aacbf8b58c5a9ae2c1b82de668f278 [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,
35 options="\n".join(map(lambda x: x.decode('utf-8'), fiscal_regimes))),
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,
40 options="\n".join(map(lambda x: x.decode('utf-8'), vat_collectability_options))),
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',
60 options="\n" + "\n".join(map(lambda x: x.decode('utf-8'), tax_exemption_reasons))),
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,
83 options="\n".join(map(lambda x: x.decode('utf-8'), mode_of_payment_codes)))
84 ],
85 'Payment Schedule': [
86 dict(fieldname='mode_of_payment_code', label='Code',
87 fieldtype='Select', insert_after='mode_of_payment', print_hide=1,
88 options="\n".join(map(lambda x: x.decode('utf-8'), mode_of_payment_codes)),
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"),
93 dict(fieldname='bank_account_name', label='Bank Account Name',
94 fieldtype='Data', insert_after='bank_account', print_hide=1,
95 fetch_from="bank_account.account_name", read_only=1),
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),
102 ],
103 "Sales Invoice": [
104 dict(fieldname='vat_collectability', label='VAT Collectability',
105 fieldtype='Select', insert_after='taxes_and_charges', print_hide=1,
106 options="\n".join(map(lambda x: x.decode('utf-8'), vat_collectability_options)),
107 fetch_from="company.vat_collectability"),
108 dict(fieldname='sb_e_invoicing_reference', label='E-Invoicing',
109 fieldtype='Section Break', insert_after='pos_total_qty', print_hide=1),
110 dict(fieldname='company_tax_id', label='Company Tax ID',
111 fieldtype='Data', insert_after='sb_e_invoicing_reference', print_hide=1, read_only=1,
112 fetch_from="company.tax_id"),
113 dict(fieldname='company_fiscal_code', label='Company Fiscal Code',
114 fieldtype='Data', insert_after='company_tax_id', print_hide=1, read_only=1,
115 fetch_from="company.fiscal_code"),
116 dict(fieldname='company_fiscal_regime', label='Company Fiscal Regime',
117 fieldtype='Data', insert_after='company_fiscal_code', print_hide=1, read_only=1,
118 fetch_from="company.fiscal_regime"),
119 dict(fieldname='cb_e_invoicing_reference', fieldtype='Column Break',
120 insert_after='company_fiscal_regime', print_hide=1),
121 dict(fieldname='customer_fiscal_code', label='Customer Fiscal Code',
122 fieldtype='Data', insert_after='cb_e_invoicing_reference', read_only=1,
123 fetch_from="customer.fiscal_code"),
124 ],
125 'Purchase Invoice Item': invoice_item_fields,
Gauravf1e28e02019-02-13 16:46:24 +0530126 'Sales Order Item': invoice_item_fields,
127 'Delivery Note Item': invoice_item_fields,
Saurabh9fcfc632019-02-20 13:03:50 +0530128 'Sales Invoice Item': invoice_item_fields,
Gauravf1e28e02019-02-13 16:46:24 +0530129 'Quotation Item': invoice_item_fields,
130 'Purchase Order Item': invoice_item_fields,
131 'Purchase Receipt Item': invoice_item_fields,
132 'Supplier Quotation Item': invoice_item_fields,
Saurabh9fcfc632019-02-20 13:03:50 +0530133 'Address': [
134 dict(fieldname='country_code', label='Country Code',
135 fieldtype='Data', insert_after='country', print_hide=1, read_only=1,
136 fetch_from="country.code"),
137 dict(fieldname='state_code', label='State Code',
138 fieldtype='Data', insert_after='state', print_hide=1)
139 ]
140 }
Gaurava4aa80f2019-01-06 12:40:28 +0530141
Saurabh9fcfc632019-02-20 13:03:50 +0530142 create_custom_fields(custom_fields, ignore_validate = frappe.flags.in_patch, update=update)
Gauravf1e28e02019-02-13 16:46:24 +0530143
144def setup_report():
Saurabh9fcfc632019-02-20 13:03:50 +0530145 report_name = 'Electronic Invoice Register'
Gauravf1e28e02019-02-13 16:46:24 +0530146
Saurabh9fcfc632019-02-20 13:03:50 +0530147 frappe.db.sql(""" update `tabReport` set disabled = 0 where
148 name = %s """, report_name)
Gauravf1e28e02019-02-13 16:46:24 +0530149
Saurabh9fcfc632019-02-20 13:03:50 +0530150 if not frappe.db.get_value('Custom Role', dict(report=report_name)):
151 frappe.get_doc(dict(
152 doctype='Custom Role',
153 report=report_name,
154 roles= [
155 dict(role='Accounts User'),
156 dict(role='Accounts Manager')
157 ]
158 )).insert()