add filter view for shops of user
This commit is contained in:
parent
89802f6a91
commit
a2032a2c78
|
@ -12,16 +12,21 @@ def register():
|
||||||
company.ConnectionCompanies,
|
company.ConnectionCompanies,
|
||||||
sale.Sale,
|
sale.Sale,
|
||||||
sale.SaleIncomeDailyStart,
|
sale.SaleIncomeDailyStart,
|
||||||
|
sale.SaleMonthByShopStart,
|
||||||
|
sale.SaleGoalAnnualRankingStart,
|
||||||
|
sale.SaleDetailedStart,
|
||||||
|
sale.ShopDailySummaryStart,
|
||||||
account.PrintBalanceSheetCOLGAAPStart,
|
account.PrintBalanceSheetCOLGAAPStart,
|
||||||
account.PrintIncomeStatementCOLGAAPStart,
|
account.PrintIncomeStatementCOLGAAPStart,
|
||||||
module='syncronize_companies', type_='model')
|
module='syncronize_companies', type_='model')
|
||||||
Pool.register(
|
Pool.register(
|
||||||
sale.SaleIncomeDailyReport,
|
sale.SaleDailyReport,
|
||||||
|
sale.SaleDetailedReport,
|
||||||
|
sale.PortfolioDetailedReport,
|
||||||
account.BalanceSheetCOLGAAP,
|
account.BalanceSheetCOLGAAP,
|
||||||
account.IncomeStatementCOLGAAP,
|
account.IncomeStatementCOLGAAP,
|
||||||
module='syncronize_companies', type_='report')
|
module='syncronize_companies', type_='report')
|
||||||
Pool.register(
|
Pool.register(
|
||||||
sale.SaleIncomeDaily,
|
|
||||||
account.PrintBalanceSheetCOLGAAP,
|
account.PrintBalanceSheetCOLGAAP,
|
||||||
account.PrintIncomeStatementCOLGAAP,
|
account.PrintIncomeStatementCOLGAAP,
|
||||||
module='syncronize_companies', type_='wizard')
|
module='syncronize_companies', type_='wizard')
|
||||||
|
|
36
account.xml
36
account.xml
|
@ -15,6 +15,42 @@
|
||||||
<field name="name">print_income_statement_colgaap_start_form</field>
|
<field name="name">print_income_statement_colgaap_start_form</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.rule.group" id="rule_group_voucher">
|
||||||
|
<field name="model" search="[('model', '=', 'account.voucher')]"/>
|
||||||
|
<field name="default_p" eval="False"/>
|
||||||
|
<field name="global_p" eval="False"/>
|
||||||
|
</record>
|
||||||
|
<record model="ir.rule" id="rule_voucher1">
|
||||||
|
<field name="domain"
|
||||||
|
eval="[('create_uid', '=', Eval('user', {}).get('id', []))]"
|
||||||
|
pyson="1"/>
|
||||||
|
<field name="rule_group" ref="rule_group_voucher"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.rule.group" id="rule_group_purchase">
|
||||||
|
<field name="model" search="[('model', '=', 'purchase.purchase')]"/>
|
||||||
|
<field name="default_p" eval="False"/>
|
||||||
|
<field name="global_p" eval="False"/>
|
||||||
|
</record>
|
||||||
|
<record model="ir.rule" id="rule_purchase1">
|
||||||
|
<field name="domain"
|
||||||
|
eval="[('create_uid', '=', Eval('user', {}).get('id', []))]"
|
||||||
|
pyson="1"/>
|
||||||
|
<field name="rule_group" ref="rule_group_purchase"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.rule.group" id="rule_group_party">
|
||||||
|
<field name="model" search="[('model', '=', 'party.party')]"/>
|
||||||
|
<field name="default_p" eval="False"/>
|
||||||
|
<field name="global_p" eval="False"/>
|
||||||
|
</record>
|
||||||
|
<record model="ir.rule" id="rule_party1">
|
||||||
|
<field name="domain"
|
||||||
|
eval="[('create_uid', '=', Eval('user', {}).get('id', []))]"
|
||||||
|
pyson="1"/>
|
||||||
|
<field name="rule_group" ref="rule_group_party"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
</tryton>
|
</tryton>
|
||||||
|
|
269
sale.py
269
sale.py
|
@ -14,8 +14,9 @@ from trytond.wizard import (
|
||||||
from trytond.report import Report
|
from trytond.report import Report
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'SaleIncomeDailyStart', 'SaleIncomeDaily',
|
'SaleIncomeDailyStart', 'SaleDailyReport',
|
||||||
'SaleIncomeDailyReport',
|
'SaleMonthByShopStart', 'SaleGoalMonthRankingReport', 'SaleDetailedStart',
|
||||||
|
'SaleDetailedReport', 'ShopDailySummaryStart', 'PortfolioDetailedReport'
|
||||||
]
|
]
|
||||||
|
|
||||||
_ZERO = Decimal('0.00')
|
_ZERO = Decimal('0.00')
|
||||||
|
@ -24,74 +25,226 @@ _ZERO = Decimal('0.00')
|
||||||
class Sale(metaclass=PoolMeta):
|
class Sale(metaclass=PoolMeta):
|
||||||
__name__ = 'sale.sale'
|
__name__ = 'sale.sale'
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_records_income_daily_report(cls, args, ctx):
|
|
||||||
report_context = {}
|
|
||||||
pool = Pool()
|
|
||||||
Report = pool._pool['TODOREPUESTOS']['report']['sale_pos.report_sale_detailed']
|
|
||||||
report_context = Report.get_context({}, args['data'])
|
|
||||||
return report_context
|
|
||||||
|
|
||||||
|
|
||||||
class SaleIncomeDailyStart(metaclass=PoolMeta):
|
class SaleIncomeDailyStart(metaclass=PoolMeta):
|
||||||
__name__ = 'sale_pos.sale_income_daily.start'
|
__name__ = 'sale_pos.sale_income_daily.start'
|
||||||
|
|
||||||
sincronize = fields.Boolean('Syncronize')
|
@classmethod
|
||||||
|
def __setup__(cls):
|
||||||
|
super(SaleIncomeDailyStart, cls).__setup__()
|
||||||
|
cls.shop.domain.append(
|
||||||
|
('id', 'in', Eval('context', {}).get('shops', -1))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SaleIncomeDaily(metaclass=PoolMeta):
|
class SaleDailyReport(metaclass=PoolMeta):
|
||||||
__name__ = 'sale_pos.sale_income_daily'
|
__name__ = 'sale_goal.sale_daily_report'
|
||||||
|
|
||||||
def do_print_(self, action):
|
|
||||||
action, data = super(SaleIncomeDaily, self).do_print_(action)
|
|
||||||
data['sincronize'] = self.start.sincronize
|
|
||||||
return action, data
|
|
||||||
|
|
||||||
|
|
||||||
class SaleIncomeDailyReport(metaclass=PoolMeta):
|
|
||||||
__name__ = 'sale_pos.sale_income_daily_report'
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_context(cls, records, data):
|
def get_context(cls, records, data):
|
||||||
report_context = super(SaleIncomeDailyReport, cls).get_context(records, data)
|
# report_context = super(SaleDailyReport, cls).get_context(records, data)
|
||||||
Company = Pool().get('company.company')
|
report_context = {}
|
||||||
|
pool = Pool()
|
||||||
|
Sale = pool.get('sale.sale')
|
||||||
|
User = pool.get('res.user')
|
||||||
|
Company = pool.get('company.company')
|
||||||
company = Company(data['company'])
|
company = Company(data['company'])
|
||||||
result = {}
|
Journal = pool.get('account.statement.journal')
|
||||||
sync = data['sincronize']
|
user_ = User(Transaction().user)
|
||||||
if sync:
|
|
||||||
date_ = {
|
dom_sales = [
|
||||||
'__class__': 'date',
|
('company', '=', data['company']),
|
||||||
'year': data['date'].year,
|
('sale_date', '=', data['sale_date']),
|
||||||
'month': data['date'].month,
|
('number', '!=', None),
|
||||||
'day': data['date'].day,
|
]
|
||||||
|
states_sale = ['confirmed', 'processing', 'done']
|
||||||
|
if data['include_canceled']:
|
||||||
|
states_sale.append('cancel')
|
||||||
|
dom_sales.append(('state', 'in', states_sale))
|
||||||
|
|
||||||
|
journal_name = ''
|
||||||
|
if data['journal']:
|
||||||
|
dom_sales.append(('payments.statement.journal', '=', data['journal']))
|
||||||
|
journal = Journal(data['journal'])
|
||||||
|
journal_name = journal.name.upper()
|
||||||
|
|
||||||
|
ctx = {
|
||||||
|
'company': user_.company.id,
|
||||||
|
'user': user_.id,
|
||||||
|
'shops': [s.id for s in user_.shops],
|
||||||
|
'shop': user_.shop.id,
|
||||||
}
|
}
|
||||||
data['date'] = date_
|
with Transaction().set_context(ctx):
|
||||||
data['sincronize'] = [False]
|
sales = Sale.search(dom_sales, order=[('number', 'ASC')])
|
||||||
data['shop'] = None
|
|
||||||
|
|
||||||
args = {
|
untaxed_amount_ = []
|
||||||
'records': records,
|
tax_amount_ = []
|
||||||
'data': data,
|
total_amount_ = []
|
||||||
}
|
total_amount_ = []
|
||||||
for sync in company.connection_companies:
|
total_journal_paid_ = []
|
||||||
api_ = 'http://' + sync.api_connection + '/'+ sync.database
|
sequence = 0
|
||||||
route = api_ + '/' + 'report_context'
|
|
||||||
data_ = json.dumps({
|
|
||||||
'database': sync.database,
|
|
||||||
'report_name': 'sale_pos.sale_income_daily_report',
|
|
||||||
'args': args,
|
|
||||||
})
|
|
||||||
res = requests.get(route, data=data_)
|
|
||||||
print(res)
|
|
||||||
print(res.text)
|
|
||||||
result = res.json()
|
|
||||||
|
|
||||||
for k in result.keys():
|
for sale in sales:
|
||||||
if isinstance(result[k], (int, float, Decimal)):
|
sequence += 1
|
||||||
report_context[k] += int(result[k])
|
setattr(sale, 'sequence', sequence)
|
||||||
elif isinstance(result[k], list):
|
journal_paid = _ZERO
|
||||||
report_context[k].extend(result[k])
|
if data['journal'] and sale.state != 'cancel':
|
||||||
if k == 'shop':
|
for p in sale.payments:
|
||||||
report_context[k] += result[k] + ' '
|
if p.statement.journal.id == data['journal']:
|
||||||
|
journal_paid += p.amount
|
||||||
|
total_journal_paid_.append(journal_paid)
|
||||||
|
|
||||||
|
setattr(sale, 'journal_paid', journal_paid)
|
||||||
|
if not hasattr(sale, 'sale_device'):
|
||||||
|
setattr(sale, 'sale_device', None)
|
||||||
|
if sale.state == 'cancel':
|
||||||
|
continue
|
||||||
|
|
||||||
|
untaxed_amount_.append(sale.untaxed_amount)
|
||||||
|
tax_amount_.append(sale.tax_amount)
|
||||||
|
total_amount_.append(sale.total_amount)
|
||||||
|
|
||||||
|
report_context['data'] = data
|
||||||
|
report_context['records'] = sales
|
||||||
|
report_context['total_amount'] = sum(total_amount_)
|
||||||
|
report_context['tax_amount'] = sum(tax_amount_)
|
||||||
|
report_context['untaxed_amount'] = sum(untaxed_amount_)
|
||||||
|
report_context['date'] = data['sale_date']
|
||||||
|
report_context['company'] = company.party.name
|
||||||
|
report_context['journal'] = journal_name
|
||||||
|
report_context['total_journal_paid'] = sum(total_journal_paid_)
|
||||||
return report_context
|
return report_context
|
||||||
|
|
||||||
|
|
||||||
|
class SaleMonthByShopStart(metaclass=PoolMeta):
|
||||||
|
__name__ = 'sale_goal.sale_month_shop.start'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __setup__(cls):
|
||||||
|
super(SaleMonthByShopStart, cls).__setup__()
|
||||||
|
cls.shop.domain.append(
|
||||||
|
('id', 'in', Eval('context', {}).get('shops', -1))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class SaleGoalAnnualRankingStart(metaclass=PoolMeta):
|
||||||
|
__name__ = 'sale_goal.annual_ranking.start'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __setup__(cls):
|
||||||
|
super(SaleGoalAnnualRankingStart, cls).__setup__()
|
||||||
|
cls.shop.domain.append(
|
||||||
|
('id', 'in', Eval('context', {}).get('shops', -1))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class SaleDetailedStart(metaclass=PoolMeta):
|
||||||
|
__name__ = 'sale_pos.sale_detailed.start'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __setup__(cls):
|
||||||
|
super(SaleDetailedStart, cls).__setup__()
|
||||||
|
cls.shop.domain.append(
|
||||||
|
('id', 'in', Eval('context', {}).get('shops', -1))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class SaleDetailedReport(metaclass=PoolMeta):
|
||||||
|
__name__ = 'sale_pos.report_sale_detailed'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_context(cls, records, data):
|
||||||
|
# report_context = super(SaleDetailedReport, cls).get_context(records, data)
|
||||||
|
report_context = {}
|
||||||
|
pool = Pool()
|
||||||
|
|
||||||
|
Sale = pool.get('sale.sale')
|
||||||
|
SaleLine = pool.get('sale.line')
|
||||||
|
Company = pool.get('company.company')
|
||||||
|
|
||||||
|
User = pool.get('res.user')
|
||||||
|
user_ = User(Transaction().user)
|
||||||
|
ctx = {
|
||||||
|
'company': user_.company.id,
|
||||||
|
'user': user_.id,
|
||||||
|
'shops': [s.id for s in user_.shops],
|
||||||
|
'shop': user_.shop.id,
|
||||||
|
}
|
||||||
|
|
||||||
|
sales_line_dom = [
|
||||||
|
('sale.sale_date', '>=', data['start_date']),
|
||||||
|
('sale.sale_date', '<=', data['end_date']),
|
||||||
|
('sale.company', '=', data['company']),
|
||||||
|
('sale.state', 'in', ['processing', 'done']),
|
||||||
|
]
|
||||||
|
if data['salesman']:
|
||||||
|
sales_line_dom.append(
|
||||||
|
('sale.salesman', '=', data['salesman'])
|
||||||
|
)
|
||||||
|
if data['shop']:
|
||||||
|
sales_line_dom.append(
|
||||||
|
('sale.shop', '=', data['shop'])
|
||||||
|
)
|
||||||
|
if data['party']:
|
||||||
|
sales_line_dom.append(
|
||||||
|
('sale.party', '=', data['party'])
|
||||||
|
)
|
||||||
|
if data['product']:
|
||||||
|
sales_line_dom.append(
|
||||||
|
('product', '=', data['product'])
|
||||||
|
)
|
||||||
|
|
||||||
|
with Transaction().set_context(ctx):
|
||||||
|
start_lines = SaleLine.search(sales_line_dom, order=[('sale.sale_date', 'ASC')])
|
||||||
|
|
||||||
|
lines = []
|
||||||
|
amount = []
|
||||||
|
amount_w_tax = []
|
||||||
|
for line in start_lines:
|
||||||
|
if line.type == 'line' and not line.product:
|
||||||
|
Sale.raise_user_error('sale_not_product', line.sale.number)
|
||||||
|
|
||||||
|
is_invoiced = False
|
||||||
|
if line.sale.invoices:
|
||||||
|
for inv in line.sale.invoices:
|
||||||
|
if inv.state not in ['draft', 'cancel']:
|
||||||
|
is_invoiced = True
|
||||||
|
if is_invoiced:
|
||||||
|
lines.append(line)
|
||||||
|
amount.append(line.amount)
|
||||||
|
amount_w_tax.append(line.amount_w_tax)
|
||||||
|
else:
|
||||||
|
lines.append(line)
|
||||||
|
amount.append(line.amount)
|
||||||
|
amount_w_tax.append(line.amount_w_tax)
|
||||||
|
|
||||||
|
report_context['data'] = data
|
||||||
|
report_context['amount'] = sum(amount)
|
||||||
|
report_context['amount_w_tax'] = sum(amount_w_tax)
|
||||||
|
report_context['records'] = lines
|
||||||
|
report_context['company'] = Company(data['company'])
|
||||||
|
return report_context
|
||||||
|
|
||||||
|
|
||||||
|
class ShopDailySummaryStart(metaclass=PoolMeta):
|
||||||
|
__name__ = 'sale_pos.shop_daily_summary.start'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __setup__(cls):
|
||||||
|
super(ShopDailySummaryStart, cls).__setup__()
|
||||||
|
cls.shop.domain.append(
|
||||||
|
('id', 'in', Eval('context', {}).get('shops', -1))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PortfolioDetailedReport(Report):
|
||||||
|
__name__ = 'party.portfolio_detailed.report'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_domain_invoice(cls, domain, data):
|
||||||
|
User = Pool().get('res.user')
|
||||||
|
user = User(Transaction().user)
|
||||||
|
shops = [s.id for s in user.shops]
|
||||||
|
dom = [('shop', 'in', shops)]
|
||||||
|
domain.extend(dom)
|
||||||
|
return domain
|
||||||
|
|
4
sale.xml
4
sale.xml
|
@ -3,11 +3,11 @@
|
||||||
<tryton>
|
<tryton>
|
||||||
<data>
|
<data>
|
||||||
<!-- report Income Daily report -->
|
<!-- report Income Daily report -->
|
||||||
<record model="ir.ui.view" id="sincronize_income_daily_start_view_form">
|
<!-- <record model="ir.ui.view" id="sincronize_income_daily_start_view_form">
|
||||||
<field name="model">sale_pos.sale_income_daily.start</field>
|
<field name="model">sale_pos.sale_income_daily.start</field>
|
||||||
<field name="inherit" ref="sale_pos.sale_income_daily_start_view_form"/>
|
<field name="inherit" ref="sale_pos.sale_income_daily_start_view_form"/>
|
||||||
<field name="name">sale_income_daily_start_form</field>
|
<field name="name">sale_income_daily_start_form</field>
|
||||||
</record>
|
</record> -->
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ depends:
|
||||||
company
|
company
|
||||||
sale
|
sale
|
||||||
sale_pos
|
sale_pos
|
||||||
|
invoice_report
|
||||||
xml:
|
xml:
|
||||||
company.xml
|
company.xml
|
||||||
sale.xml
|
sale.xml
|
||||||
|
|
Loading…
Reference in New Issue