Browse Source

[ADD] demo data

[REF] factor code
[UPD] fr translation and pot file
pull/282/head
Sylvain LE GAL 7 years ago
parent
commit
eb982a3f4b
  1. 6
      pos_cash_move_reason/__openerp__.py
  2. 21
      pos_cash_move_reason/demo/product_template.xml
  3. 38
      pos_cash_move_reason/i18n/fr.po
  4. 24
      pos_cash_move_reason/i18n/pos_cash_move_reason.pot
  5. 17
      pos_cash_move_reason/tests/test_pos_cash_move_reason.py
  6. 63
      pos_cash_move_reason/wizard/pos_box.py
  7. 48
      pos_cash_move_reason/wizard/pos_box.xml

6
pos_cash_move_reason/__openerp__.py

@ -5,10 +5,11 @@
'name': "POS cash in-out reason", 'name': "POS cash in-out reason",
'summary': """""", 'summary': """""",
'author': 'ACSONE SA/NV,' 'author': 'ACSONE SA/NV,'
'GRAP,'
'Odoo Community Association (OCA)', 'Odoo Community Association (OCA)',
'website': "http://acsone.eu", 'website': "http://acsone.eu",
'category': 'POS', 'category': 'POS',
'version': '8.0.1.0.0',
'version': '8.0.2.0.0',
'license': 'AGPL-3', 'license': 'AGPL-3',
'depends': [ 'depends': [
'point_of_sale', 'point_of_sale',
@ -16,4 +17,7 @@
'data': [ 'data': [
'wizard/pos_box.xml', 'wizard/pos_box.xml',
], ],
'demo': [
'demo/product_template.xml',
],
} }

21
pos_cash_move_reason/demo/product_template.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<openerp><data>
<record id="income_reason" model="product.template">
<field name="name">Miscellaneous income</field>
<field name="income_pdt" eval="True" />
<field name="property_account_income" ref="account.o_income"/>
</record>
<record id="expense_reason" model="product.template">
<field name="name">Miscellaneous expense</field>
<field name="expense_pdt" eval="True" />
<field name="property_account_expense" ref="account.a_expense"/>
</record>
</data></openerp>

38
pos_cash_move_reason/i18n/fr.po

@ -6,8 +6,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 8.0\n" "Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-04-12 11:10+0000\n"
"PO-Revision-Date: 2016-04-12 11:10+0000\n"
"POT-Creation-Date: 2018-02-15 13:30+0000\n"
"PO-Revision-Date: 2018-02-15 13:30+0000\n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"Language: \n" "Language: \n"
@ -18,31 +18,35 @@ msgstr ""
#. module: pos_cash_move_reason #. module: pos_cash_move_reason
#: code:addons/pos_cash_move_reason/wizard/pos_box.py:36 #: code:addons/pos_cash_move_reason/wizard/pos_box.py:36
#: code:addons/pos_cash_move_reason/wizard/pos_box.py:39
#, python-format #, python-format
msgid "Description" msgid "Description"
msgstr "Description" msgstr "Description"
#. module: pos_cash_move_reason #. module: pos_cash_move_reason
#: field:cash.box.in,product_id:0 field:cash.box.out,product_id:0
#: model:product.template,name:pos_cash_move_reason.expense_reason
msgid "Miscellaneous expense"
msgstr "Dépense diverse"
#. module: pos_cash_move_reason
#: model:product.template,name:pos_cash_move_reason.income_reason
msgid "Miscellaneous income"
msgstr "Revenu divers"
#. module: pos_cash_move_reason
#: field:cash.box.in,product_id:0
#: field:cash.box.out,product_id:0
msgid "Reason" msgid "Reason"
msgstr "Motif" msgstr "Motif"
#. module: pos_cash_move_reason #. module: pos_cash_move_reason
#: code:addons/pos_cash_move_reason/wizard/pos_box.py:84
#: code:addons/pos_cash_move_reason/wizard/pos_box.py:62
#, python-format #, python-format
msgid ""
"You have to define an\n"
" expense account on the related product"
msgstr ""
"Vous devez définir un\n"
" compte de charge sur le produit lié"
msgid "You have to define an expense account on the related product %s"
msgstr "Vous devez définir un compte de charge sur le produit lié %s"
#. module: pos_cash_move_reason #. module: pos_cash_move_reason
#: code:addons/pos_cash_move_reason/wizard/pos_box.py:60
#: code:addons/pos_cash_move_reason/wizard/pos_box.py:55
#, python-format #, python-format
msgid ""
"You have to define an\n"
" income account on the related product"
msgstr ""
"Vous devez définir un\n"
" compte de produit sur le produit lié"
msgid "You have to define an income account on the related product %s"
msgstr "Vous devez définir un compte de produit sur le produit lié %s"

24
pos_cash_move_reason/i18n/pos_cash_move_reason.pot

@ -6,6 +6,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 8.0\n" "Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-02-15 13:46+0000\n"
"PO-Revision-Date: 2018-02-15 13:46+0000\n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -14,11 +16,21 @@ msgstr ""
"Plural-Forms: \n" "Plural-Forms: \n"
#. module: pos_cash_move_reason #. module: pos_cash_move_reason
#: code:addons/pos_cash_move_reason/wizard/pos_box.py:36
#: code:addons/pos_cash_move_reason/wizard/pos_box.py:39
#, python-format #, python-format
msgid "Description" msgid "Description"
msgstr "" msgstr ""
#. module: pos_cash_move_reason
#: model:product.template,name:pos_cash_move_reason.expense_reason
msgid "Miscellaneous expense"
msgstr ""
#. module: pos_cash_move_reason
#: model:product.template,name:pos_cash_move_reason.income_reason
msgid "Miscellaneous income"
msgstr ""
#. module: pos_cash_move_reason #. module: pos_cash_move_reason
#: field:cash.box.in,product_id:0 #: field:cash.box.in,product_id:0
#: field:cash.box.out,product_id:0 #: field:cash.box.out,product_id:0
@ -26,16 +38,14 @@ msgid "Reason"
msgstr "" msgstr ""
#. module: pos_cash_move_reason #. module: pos_cash_move_reason
#: code:addons/pos_cash_move_reason/wizard/pos_box.py:84
#: code:addons/pos_cash_move_reason/wizard/pos_box.py:62
#, python-format #, python-format
msgid "You have to define an\n"
" expense account on the related product"
msgid "You have to define an expense account on the related product %s"
msgstr "" msgstr ""
#. module: pos_cash_move_reason #. module: pos_cash_move_reason
#: code:addons/pos_cash_move_reason/wizard/pos_box.py:60
#: code:addons/pos_cash_move_reason/wizard/pos_box.py:55
#, python-format #, python-format
msgid "You have to define an\n"
" income account on the related product"
msgid "You have to define an income account on the related product %s"
msgstr "" msgstr ""

17
pos_cash_move_reason/tests/test_pos_cash_move_reason.py

@ -18,13 +18,11 @@ class TestPosCashMoveReason(common.TransactionCase):
self.cash_journal = self.env.ref('account.cash_journal') self.cash_journal = self.env.ref('account.cash_journal')
self.income_account = self.env.ref('account.o_income') self.income_account = self.env.ref('account.o_income')
self.expense_account = self.env.ref('account.a_expense') self.expense_account = self.env.ref('account.a_expense')
self.income_reason = self.env.ref('pos_cash_move_reason.income_reason')
self.expense_reason = self.env.ref(
'pos_cash_move_reason.expense_reason')
def test01(self): def test01(self):
# I create one move reason
vals = {'name': 'Miscellaneous income',
'property_account_income': self.income_account.id,
'income_pdt': True}
move_reason = self.cash_move_reason_obj.create(vals)
# I set cash control on cash journal # I set cash control on cash journal
self.cash_journal.cash_control = True self.cash_journal.cash_control = True
# I create and open a new session # I create and open a new session
@ -44,7 +42,7 @@ class TestPosCashMoveReason(common.TransactionCase):
# I create a cash in # I create a cash in
cash_in = self.cash_in_obj.with_context(ctx).create( cash_in = self.cash_in_obj.with_context(ctx).create(
{'name': 'Initialization', {'name': 'Initialization',
'product_id': move_reason.id,
'product_id': self.income_reason.id,
'amount': 500.0}) 'amount': 500.0})
cash_in.with_context(ctx).run() cash_in.with_context(ctx).run()
# I close the session # I close the session
@ -63,11 +61,6 @@ class TestPosCashMoveReason(common.TransactionCase):
self.assertEquals(len(move_line.ids), 1) self.assertEquals(len(move_line.ids), 1)
def test02(self): def test02(self):
# I create one move reason
vals = {'name': 'Miscellaneous expense',
'property_account_expense': self.expense_account.id,
'expense_pdt': True}
move_reason = self.cash_move_reason_obj.create(vals)
# I set cash control on cash journal # I set cash control on cash journal
self.cash_journal.cash_control = True self.cash_journal.cash_control = True
# I create and open a new session # I create and open a new session
@ -87,7 +80,7 @@ class TestPosCashMoveReason(common.TransactionCase):
# I create a cash out # I create a cash out
cash_out = self.cash_out_obj.with_context(ctx).create( cash_out = self.cash_out_obj.with_context(ctx).create(
{'name': 'Miscellaneous expense', {'name': 'Miscellaneous expense',
'product_id': move_reason.id,
'product_id': self.expense_reason.id,
'amount': 500.0}) 'amount': 500.0})
cash_out.with_context(ctx).run() cash_out.with_context(ctx).run()
# I close the session # I close the session

63
pos_cash_move_reason/wizard/pos_box.py

@ -12,6 +12,9 @@ import simplejson
class PosBoxCashMoveReason(PosBox): class PosBoxCashMoveReason(PosBox):
_register = False _register = False
product_id = fields.Many2one(
comodel_name='product.template', string='Reason')
@api.onchange('product_id') @api.onchange('product_id')
def onchange_reason(self): def onchange_reason(self):
for record in self: for record in self:
@ -37,50 +40,36 @@ class PosBoxCashMoveReason(PosBox):
res['arch'] = etree.tostring(doc) res['arch'] = etree.tostring(doc)
return res return res
class PosBoxIn(PosBoxCashMoveReason):
_inherit = 'cash.box.in'
product_id = fields.Many2one(
comodel_name='product.template', string='Reason',
domain="[('income_pdt', '=', True)]")
@api.model @api.model
def _compute_values_for_statement_line(self, box, record): def _compute_values_for_statement_line(self, box, record):
values = super(PosBoxIn, self)._compute_values_for_statement_line(
box, record)
values = super(
PosBoxCashMoveReason, self)._compute_values_for_statement_line(
box, record)
if self.env.context.get('active_model', '') == 'pos.session': if self.env.context.get('active_model', '') == 'pos.session':
if box.product_id.id:
product = box.product_id
product = box.product_id
account_id = False
if self._name == 'cash.box.in':
account_id = product.property_account_income.id or\ account_id = product.property_account_income.id or\
product.categ_id.property_account_income_categ.id product.categ_id.property_account_income_categ.id
if account_id:
values['account_id'] = account_id
else:
raise exceptions.Warning(_("""You have to define an
income account on the related product"""))
if not account_id:
raise exceptions.Warning(_(
"You have to define an income account on the related"
" product %s") % (product.name))
elif self._name == 'cash.box.out':
account_id = product.property_account_expense.id or\
product.categ_id.property_account_expense_categ.id
if not account_id:
raise exceptions.Warning(_(
"You have to define an expense account on the related"
" product %s") % (product.name))
values['account_id'] = account_id
return values return values
class PosBoxOut(PosBoxCashMoveReason):
_inherit = 'cash.box.out'
# the following lines are required for correct inheritance mechanism
class PosBoxIn(PosBoxCashMoveReason):
_inherit = 'cash.box.in'
product_id = fields.Many2one(
comodel_name='product.template', string='Reason',
domain="[('expense_pdt', '=', True)]")
@api.model
def _compute_values_for_statement_line(self, box, record):
values = super(PosBoxOut, self)._compute_values_for_statement_line(
box, record)
if self.env.context.get('active_model', '') == 'pos.session':
if box.product_id.id:
product = box.product_id
account_id = product.property_account_expense.id or\
product.categ_id.property_account_expense_categ.id
if account_id:
values['account_id'] = account_id
else:
raise exceptions.Warning(_("""You have to define an
expense account on the related product"""))
return values
class PosBoxOut(PosBoxCashMoveReason):
_inherit = 'cash.box.out'

48
pos_cash_move_reason/wizard/pos_box.xml

@ -1,26 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="cash_box_in_form">
<field name="name">cash.box.in.form</field>
<field name="model">cash.box.in</field>
<field name="inherit_id" ref="account.cash_box_in_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="before">
<field name="product_id" required="1" class="oe_inline" />
</xpath>
</field>
</record>
<openerp><data>
<record model="ir.ui.view" id="cash_box_out_form">
<field name="name">cash.box.out.form</field>
<field name="model">cash.box.out</field>
<field name="inherit_id" ref="account.cash_box_out_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="before">
<field name="product_id" required="1" class="oe_inline"/>
</xpath>
</field>
</record>
</data>
</openerp>
<record model="ir.ui.view" id="cash_box_in_form">
<field name="model">cash.box.in</field>
<field name="inherit_id" ref="account.cash_box_in_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="before">
<field name="product_id" required="1" class="oe_inline"
domain="[('income_pdt', '=', True)]"/>
</xpath>
</field>
</record>
<record model="ir.ui.view" id="cash_box_out_form">
<field name="model">cash.box.out</field>
<field name="inherit_id" ref="account.cash_box_out_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="before">
<field name="product_id" required="1" class="oe_inline"
domain="[('expense_pdt', '=', True)]"/>
</xpath>
</field>
</record>
</data></openerp>
Loading…
Cancel
Save